generated from TrueCloudLab/basic
[#1] chain: Fix ID type from string to bytes
ID may be non UTF-8 string, so from developers POV it is just byte slice. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
5f13d91c0d
commit
dd0f582fc3
8 changed files with 57 additions and 60 deletions
|
@ -19,7 +19,7 @@ var (
|
|||
func (c *Chain) MarshalBinary() ([]byte, error) {
|
||||
s := marshal.UInt8Size // Marshaller version
|
||||
s += marshal.UInt8Size // Chain version
|
||||
s += marshal.StringSize(string(c.ID))
|
||||
s += marshal.SliceSize(c.ID, func(byte) int { return marshal.ByteSize })
|
||||
s += marshal.SliceSize(c.Rules, ruleSize)
|
||||
s += marshal.UInt8Size // MatchType
|
||||
|
||||
|
@ -34,7 +34,7 @@ func (c *Chain) MarshalBinary() ([]byte, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
offset, err = marshal.StringMarshal(buf, offset, string(c.ID))
|
||||
offset, err = marshal.SliceMarshal(buf, offset, c.ID, marshal.ByteMarshal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -72,11 +72,11 @@ func (c *Chain) UnmarshalBinary(data []byte) error {
|
|||
return fmt.Errorf("unsupported chain version %d", chainVersion)
|
||||
}
|
||||
|
||||
idStr, offset, err := marshal.StringUnmarshal(data, offset)
|
||||
idBytes, offset, err := marshal.SliceUnmarshal(data, offset, marshal.ByteUnmarshal)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.ID = ID(idStr)
|
||||
c.ID = ID(idBytes)
|
||||
|
||||
c.Rules, offset, err = marshal.SliceUnmarshal(data, offset, unmarshalRule)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue