MCPcopy Index your code
hub / github.com/WICG/webpackage / EncodeTextString

Method EncodeTextString

go/internal/cbor/encoder.go:115–137  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

113}
114
115func (e *Encoder) EncodeTextString(s string) error {
116 // Major type 3: a text string, specifically a string of Unicode
117 // characters that is encoded as UTF-8 [RFC3629]. The format of this
118 // type is identical to that of byte strings (major type 2), that is,
119 // as with major type 2, the length gives the number of bytes. This
120 // type is provided for systems that need to interpret or display
121 // human-readable text, and allows the differentiation between
122 // unstructured bytes and text that has a specified repertoire and
123 // encoding. In contrast to formats such as JSON, the Unicode
124 // characters in this type are never escaped. Thus, a newline
125 // character (U+000A) is always represented in a string as the byte
126 // 0x0a, and never as the bytes 0x5c6e (the characters "\" and "n")
127 // or as 0x5c7530303061 (the characters "\", "u", "0", "0", "0", and
128 // "a").
129 //
130 // https://tools.ietf.org/html/rfc7049#section-2.1
131 bs := []byte(s)
132 if !utf8.Valid(bs) {
133 return ErrInvalidUTF8
134 }
135
136 return e.encodeBytes(TypeText, bs)
137}
138
139func (e *Encoder) EncodeArrayHeader(n int) error {
140 // Major type 4: an array of data items. Arrays are also called lists,

Callers 14

TestEncodeTextStringFunction · 0.95
newPrimarySectionFunction · 0.95
newManifestSectionFunction · 0.95
writePrimaryURLFunction · 0.95
writeSectionOffsetsFunction · 0.95
WriteMethod · 0.95
cborBytesMethod · 0.80
TestMapEncoderFunction · 0.80
FinalizeMethod · 0.80
newSignaturesSectionFunction · 0.80
EncodeMethod · 0.80

Calls 1

encodeBytesMethod · 0.95

Tested by 3

TestEncodeTextStringFunction · 0.76
TestMapEncoderFunction · 0.64