| 113 | } |
| 114 | |
| 115 | func (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 | |
| 139 | func (e *Encoder) EncodeArrayHeader(n int) error { |
| 140 | // Major type 4: an array of data items. Arrays are also called lists, |