diff --git a/decoder.go b/decoder.go index a536693..c843348 100644 --- a/decoder.go +++ b/decoder.go @@ -49,11 +49,6 @@ var TypeSize = struct { PublicKey int Signature int - - Tstamp int - BlockTimestamp int - - CurrencyName int }{ Byte: 1, Bool: 1, @@ -69,9 +64,11 @@ var TypeSize = struct { Float32: 4, Float64: 8, + + PublicKey: 32, + Signature: 64, } -// Decoder implements the EOS unpacking, similar to FC_BUFFER type Decoder struct { data []byte pos int @@ -281,11 +278,6 @@ func (dec *Decoder) ReadLength() (length int, err error) { return } -type peekAbleByteReader interface { - io.ByteReader - Peek(n int) ([]byte, error) -} - func readNBytes(n int, reader *Decoder) ([]byte, error) { if n == 0 { return make([]byte, 0), nil @@ -481,15 +473,6 @@ func (dec *Decoder) ReadInt16(order binary.ByteOrder) (out int16, err error) { return } -func (dec *Decoder) ReadInt64(order binary.ByteOrder) (out int64, err error) { - n, err := dec.ReadUint64(order) - out = int64(n) - if traceEnabled { - zlog.Debug("decode: read int64", zap.Int64("val", out)) - } - return -} - func (dec *Decoder) ReadUint32(order binary.ByteOrder) (out uint32, err error) { if dec.Remaining() < TypeSize.Uint32 { err = fmt.Errorf("uint32 required [%d] bytes, remaining [%d]", TypeSize.Uint32, dec.Remaining()) @@ -530,12 +513,13 @@ func (dec *Decoder) ReadUint64(order binary.ByteOrder) (out uint64, err error) { return } -func (dec *Decoder) ReadInt128(order binary.ByteOrder) (out Int128, err error) { - v, err := dec.ReadUint128(order) - if err != nil { - return +func (dec *Decoder) ReadInt64(order binary.ByteOrder) (out int64, err error) { + n, err := dec.ReadUint64(order) + out = int64(n) + if traceEnabled { + zlog.Debug("decode: read int64", zap.Int64("val", out)) } - return Int128(v), nil + return } func (dec *Decoder) ReadUint128(order binary.ByteOrder) (out Uint128, err error) { @@ -562,6 +546,14 @@ func (dec *Decoder) ReadUint128(order binary.ByteOrder) (out Uint128, err error) return } +func (dec *Decoder) ReadInt128(order binary.ByteOrder) (out Int128, err error) { + v, err := dec.ReadUint128(order) + if err != nil { + return + } + return Int128(v), nil +} + func (dec *Decoder) ReadFloat32(order binary.ByteOrder) (out float32, err error) { if dec.Remaining() < TypeSize.Float32 { err = fmt.Errorf("float32 required [%d] bytes, remaining [%d]", TypeSize.Float32, dec.Remaining()) diff --git a/encoder.go b/encoder.go index 727477a..37a7775 100644 --- a/encoder.go +++ b/encoder.go @@ -29,12 +29,12 @@ import ( ) type Encoder struct { - output io.Writer - count int + count int currentFieldOpt *option + encoding Encoding - encoding Encoding + output io.Writer } func (enc *Encoder) IsBorsh() bool { @@ -227,13 +227,6 @@ func (e *Encoder) WriteInt16(i int16, order binary.ByteOrder) (err error) { return e.WriteUint16(uint16(i), order) } -func (e *Encoder) WriteInt32(i int32, order binary.ByteOrder) (err error) { - if traceEnabled { - zlog.Debug("encode: write int32", zap.Int32("val", i)) - } - return e.WriteUint32(uint32(i), order) -} - func (e *Encoder) WriteUint32(i uint32, order binary.ByteOrder) (err error) { if traceEnabled { zlog.Debug("encode: write uint32", zap.Uint32("val", i)) @@ -243,11 +236,11 @@ func (e *Encoder) WriteUint32(i uint32, order binary.ByteOrder) (err error) { return e.toWriter(buf) } -func (e *Encoder) WriteInt64(i int64, order binary.ByteOrder) (err error) { +func (e *Encoder) WriteInt32(i int32, order binary.ByteOrder) (err error) { if traceEnabled { - zlog.Debug("encode: write int64", zap.Int64("val", i)) + zlog.Debug("encode: write int32", zap.Int32("val", i)) } - return e.WriteUint64(uint64(i), order) + return e.WriteUint32(uint32(i), order) } func (e *Encoder) WriteUint64(i uint64, order binary.ByteOrder) (err error) { @@ -259,6 +252,13 @@ func (e *Encoder) WriteUint64(i uint64, order binary.ByteOrder) (err error) { return e.toWriter(buf) } +func (e *Encoder) WriteInt64(i int64, order binary.ByteOrder) (err error) { + if traceEnabled { + zlog.Debug("encode: write int64", zap.Int64("val", i)) + } + return e.WriteUint64(uint64(i), order) +} + func (e *Encoder) WriteUint128(i Uint128, order binary.ByteOrder) (err error) { if traceEnabled { zlog.Debug("encode: write uint128", zap.Stringer("hex", i), zap.Uint64("lo", i.Lo), zap.Uint64("hi", i.Hi)) @@ -348,15 +348,19 @@ func (e *Encoder) WriteRustString(s string) (err error) { return e.WriteBytes([]byte(s), false) } -func (e *Encoder) WriteCompactU16Length(ln int) (err error) { +func (e *Encoder) WriteCompactU16(ln int) (err error) { if traceEnabled { - zlog.Debug("encode: write compact-u16 length", zap.Int("val", ln)) + zlog.Debug("encode: write compact-u16", zap.Int("val", ln)) } buf := make([]byte, 0) EncodeCompactU16Length(&buf, ln) return e.toWriter(buf) } +func (e *Encoder) WriteCompactU16Length(ln int) (err error) { + return e.WriteCompactU16(ln) +} + func reflect_writeArrayOfBytes(e *Encoder, l int, rv reflect.Value) error { arr := make([]byte, l) for i := 0; i < l; i++ { diff --git a/encoder_borsh.go b/encoder_borsh.go index 93b8a12..c1cc611 100644 --- a/encoder_borsh.go +++ b/encoder_borsh.go @@ -278,11 +278,11 @@ type BorshEnum uint8 // EmptyVariant is an empty borsh enum variant. type EmptyVariant struct{} -func (_ *EmptyVariant) MarshalWithEncoder(_ *Encoder) error { +func (*EmptyVariant) MarshalWithEncoder(_ *Encoder) error { return nil } -func (_ *EmptyVariant) UnmarshalWithDecoder(_ *Decoder) error { +func (*EmptyVariant) UnmarshalWithDecoder(_ *Decoder) error { return nil }