Skip to content

Commit

Permalink
tidy int32/int16 decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
HDT3213 committed Aug 26, 2024
1 parent 76538c6 commit e5a00e1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions core/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ func (dec *Decoder) readString() ([]byte, error) {
b, err := dec.readByte()
return []byte(strconv.Itoa(int(int8(b)))), err
case encodeInt16:
b, err := dec.readUint16()
return []byte(strconv.Itoa(int(int16(b)))), err
b, err := dec.readInt16()
return []byte(strconv.Itoa(int(b))), err
case encodeInt32:
b, err := dec.readUint32()
return []byte(strconv.Itoa(int(int32(b)))), err
b, err := dec.readInt32()
return []byte(strconv.Itoa(int(b))), err
case encodeLZF:
return dec.readLZF()
default:
Expand All @@ -106,24 +106,24 @@ func (dec *Decoder) readString() ([]byte, error) {
return res, err
}

func (dec *Decoder) readUint16() (uint16, error) {
func (dec *Decoder) readInt16() (int16, error) {
err := dec.readFull(dec.buffer[:2])
if err != nil {
return 0, fmt.Errorf("read uint16 error: %v", err)
}

i := binary.LittleEndian.Uint16(dec.buffer[:2])
return i, nil
return int16(i), nil
}

func (dec *Decoder) readUint32() (uint32, error) {
func (dec *Decoder) readInt32() (int32, error) {
err := dec.readFull(dec.buffer[:4])
if err != nil {
return 0, fmt.Errorf("read uint16 error: %v", err)
}

i := binary.LittleEndian.Uint32(dec.buffer[:4])
return i, nil
return int32(i), nil
}

func (dec *Decoder) readLiteralFloat() (float64, error) {
Expand Down

0 comments on commit e5a00e1

Please sign in to comment.