mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 22:31:21 +00:00
removed ByteSize, etc.
This commit is contained in:
@ -1,22 +1,26 @@
|
||||
package binary
|
||||
|
||||
const (
|
||||
TYPE_NIL = byte(0x00)
|
||||
TYPE_BYTE = byte(0x01)
|
||||
TYPE_INT8 = byte(0x02)
|
||||
TYPE_UINT8 = byte(0x03)
|
||||
TYPE_INT16 = byte(0x04)
|
||||
TYPE_UINT16 = byte(0x05)
|
||||
TYPE_INT32 = byte(0x06)
|
||||
TYPE_UINT32 = byte(0x07)
|
||||
TYPE_INT64 = byte(0x08)
|
||||
TYPE_UINT64 = byte(0x09)
|
||||
|
||||
TYPE_STRING = byte(0x10)
|
||||
TYPE_BYTESLICE = byte(0x11)
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
func GetBinaryType(o Binary) byte {
|
||||
const (
|
||||
TYPE_NIL = Byte(0x00)
|
||||
TYPE_BYTE = Byte(0x01)
|
||||
TYPE_INT8 = Byte(0x02)
|
||||
TYPE_UINT8 = Byte(0x03)
|
||||
TYPE_INT16 = Byte(0x04)
|
||||
TYPE_UINT16 = Byte(0x05)
|
||||
TYPE_INT32 = Byte(0x06)
|
||||
TYPE_UINT32 = Byte(0x07)
|
||||
TYPE_INT64 = Byte(0x08)
|
||||
TYPE_UINT64 = Byte(0x09)
|
||||
|
||||
TYPE_STRING = Byte(0x10)
|
||||
TYPE_BYTESLICE = Byte(0x11)
|
||||
)
|
||||
|
||||
func GetBinaryType(o Binary) Byte {
|
||||
switch o.(type) {
|
||||
case nil: return TYPE_NIL
|
||||
case Byte: return TYPE_BYTE
|
||||
@ -38,22 +42,22 @@ func GetBinaryType(o Binary) byte {
|
||||
}
|
||||
}
|
||||
|
||||
func ReadBinary(buf []byte, start int) (Binary, int) {
|
||||
typeByte := buf[start]
|
||||
switch typeByte {
|
||||
case TYPE_NIL: return nil, start+1
|
||||
case TYPE_BYTE: return ReadByte(buf[start+1:]), start+2
|
||||
case TYPE_INT8: return ReadInt8(buf[start+1:]), start+2
|
||||
case TYPE_UINT8: return ReadUInt8(buf[start+1:]), start+2
|
||||
case TYPE_INT16: return ReadInt16(buf[start+1:]), start+3
|
||||
case TYPE_UINT16: return ReadUInt16(buf[start+1:]), start+3
|
||||
case TYPE_INT32: return ReadInt32(buf[start+1:]), start+5
|
||||
case TYPE_UINT32: return ReadUInt32(buf[start+1:]), start+5
|
||||
case TYPE_INT64: return ReadInt64(buf[start+1:]), start+9
|
||||
case TYPE_UINT64: return ReadUInt64(buf[start+1:]), start+9
|
||||
func ReadBinary(r io.Reader) Binary {
|
||||
type_ := ReadByte(r)
|
||||
switch type_ {
|
||||
case TYPE_NIL: return nil
|
||||
case TYPE_BYTE: return ReadByte(r)
|
||||
case TYPE_INT8: return ReadInt8(r)
|
||||
case TYPE_UINT8: return ReadUInt8(r)
|
||||
case TYPE_INT16: return ReadInt16(r)
|
||||
case TYPE_UINT16: return ReadUInt16(r)
|
||||
case TYPE_INT32: return ReadInt32(r)
|
||||
case TYPE_UINT32: return ReadUInt32(r)
|
||||
case TYPE_INT64: return ReadInt64(r)
|
||||
case TYPE_UINT64: return ReadUInt64(r)
|
||||
|
||||
case TYPE_STRING: return ReadString(buf, start+1)
|
||||
case TYPE_BYTESLICE:return ReadByteSlice(buf, start+1)
|
||||
case TYPE_STRING: return ReadString(r)
|
||||
case TYPE_BYTESLICE:return ReadByteSlice(r)
|
||||
|
||||
default: panic("Unsupported type")
|
||||
}
|
||||
|
Reference in New Issue
Block a user