func()

in int.go [60:111]


func (d *Decoder) decInt32(flag int32) (int32, error) {
	var (
		err error
		tag byte
	)

	if flag != TAG_READ {
		tag = byte(flag)
	} else {
		tag, _ = d.ReadByte()
	}

	switch {
	case tag >= 0x80 && tag <= 0xbf:
		i8 := int8(tag - BC_INT_ZERO)
		return int32(i8), nil

	case tag >= 0xc0 && tag <= 0xcf:
		buf := []byte{tag - BC_INT_BYTE_ZERO, 0}
		_, err = io.ReadFull(d.reader, buf[1:])
		if err != nil {
			return 0, perrors.WithStack(err)
		}
		u16 := binary.BigEndian.Uint16(buf)
		i16 := int16(u16)
		return int32(i16), nil

	case tag >= 0xd0 && tag <= 0xd7:
		// Use int32 to represent int24.
		buf := []byte{0, tag - BC_INT_SHORT_ZERO, 0, 0}
		if buf[1]&0x80 != 0 {
			buf[0] = 0xff
		}
		_, err = io.ReadFull(d.reader, buf[2:])
		if err != nil {
			return 0, perrors.WithStack(err)
		}
		u32 := binary.BigEndian.Uint32(buf)
		return int32(u32), nil

	case tag == BC_INT:
		var i32 int32
		err = binary.Read(d.reader, binary.BigEndian, &i32)
		return i32, perrors.WithStack(err)

	case tag == BC_NULL:
		return int32(0), nil

	default:
		return 0, perrors.Errorf("decInt32 integer wrong tag:%#x", tag)
	}
}