transaction: implement encoding for state

This commit is contained in:
Roman Khimov 2019-08-30 19:13:19 +03:00
parent 868c9d6e8c
commit af212f496e
2 changed files with 17 additions and 1 deletions

View file

@ -29,6 +29,17 @@ func (tx *StateTX) DecodeBinary(r io.Reader) error {
// EncodeBinary implements the Payload interface.
func (tx *StateTX) EncodeBinary(w io.Writer) error {
bw := util.BinWriter{W: w}
bw.WriteVarUint(uint64(len(tx.Descriptors)))
if bw.Err != nil {
return bw.Err
}
for _, desc := range tx.Descriptors {
err := desc.EncodeBinary(w)
if err != nil {
return err
}
}
return nil
}

View file

@ -37,7 +37,12 @@ func (s *StateDescriptor) DecodeBinary(r io.Reader) error {
// EncodeBinary implements the Payload interface.
func (s *StateDescriptor) EncodeBinary(w io.Writer) error {
return nil
bw := util.BinWriter{W: w}
bw.WriteLE(s.Type)
bw.WriteBytes(s.Key)
bw.WriteBytes(s.Value)
bw.WriteString(s.Field)
return bw.Err
}
func (s *StateDescriptor) Size() int {