| 79 | } |
| 80 | |
| 81 | func (dec *Decoder) readString() ([]byte, error) { |
| 82 | length, special, err := dec.readLength() |
| 83 | if err != nil { |
| 84 | return nil, err |
| 85 | } |
| 86 | |
| 87 | if special { |
| 88 | switch length { |
| 89 | case encodeInt8: |
| 90 | b, err := dec.readByte() |
| 91 | return []byte(strconv.Itoa(int(int8(b)))), err |
| 92 | case encodeInt16: |
| 93 | b, err := dec.readInt16() |
| 94 | return []byte(strconv.Itoa(int(b))), err |
| 95 | case encodeInt32: |
| 96 | b, err := dec.readInt32() |
| 97 | return []byte(strconv.Itoa(int(b))), err |
| 98 | case encodeLZF: |
| 99 | return dec.readLZF() |
| 100 | default: |
| 101 | return []byte{}, errors.New("Unknown string encode type ") |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | res := make([]byte, length) |
| 106 | err = dec.readFull(res) |
| 107 | return res, err |
| 108 | } |
| 109 | |
| 110 | func (dec *Decoder) readInt16() (int16, error) { |
| 111 | err := dec.readFull(dec.buffer[:2]) |