@@ -60,6 +60,7 @@ func (f *Format) String() (text string) {
6060 return text
6161}
6262
63+ // Field represents a `message_field`
6364type Field struct {
6465 ID int
6566 Type FieldType
@@ -68,10 +69,15 @@ type Field struct {
6869 Skipped bool
6970}
7071
72+ // FieldType represents a `type_field`
7173type FieldType interface {
7274 fmt.Stringer
7375}
7476
77+ // FieldIntFixed is for values with a fixed length.
78+ // This is also known as the 'fixlen_integer_format'.
79+ // The encoded value can vary be between 1 and 2 times
80+ // of that of the value before encoding.
7581type FieldIntFixed struct {
7682 Length int // Length of value before encoding, encoded value can be more
7783 Value []byte
@@ -84,6 +90,8 @@ func (f FieldIntFixed) String() string {
8490 return fmt .Sprintf ("0x%x" , f .Value )
8591}
8692
93+ // FieldIntVar is using the signed integer variant of the 'varlen_integer_format'
94+ // and encodes a value as a byte sequence of 1-9 bytes depending on the value.
8795type FieldIntVar struct {
8896 Value int64
8997}
@@ -92,6 +100,8 @@ func (f FieldIntVar) String() string {
92100 return fmt .Sprintf ("%d" , f .Value )
93101}
94102
103+ // FieldUintVar is using the usigned integer variant of the 'varlen_integer_format'
104+ // and encodes a value as a byte sequence of 1-9 bytes depending on the value.
95105type FieldUintVar struct {
96106 Value uint64
97107}
@@ -100,6 +110,7 @@ func (f FieldUintVar) String() string {
100110 return fmt .Sprintf ("%d" , f .Value )
101111}
102112
113+ // FieldString is a 'string_format' field
103114type FieldString struct {
104115 Value string
105116}
@@ -118,7 +129,7 @@ func Unmarshal(data []byte, v interface{}) error {
118129 if err != nil {
119130 return err
120131 }
121- m .Version = tmpVer [0 ] / 2
132+ m .Version = tmpVer [0 ] >> 1
122133
123134 err = Unmarshal (data [messageLen :], & m .Format )
124135 if err != nil {
@@ -131,8 +142,8 @@ func Unmarshal(data []byte, v interface{}) error {
131142 if err != nil {
132143 return err
133144 }
134- m .Size = uint64 (tmpFormat [0 ] / 2 )
135- m .LastNonIgnorableField = int (tmpFormat [1 ] / 2 )
145+ m .Size = uint64 (tmpFormat [0 ] >> 1 )
146+ m .LastNonIgnorableField = int (tmpFormat [1 ] >> 1 )
136147
137148 for i := 0 ; i < len (m .Fields ); i ++ {
138149 tmpField := make ([]byte , 1 )
@@ -154,7 +165,7 @@ func Unmarshal(data []byte, v interface{}) error {
154165 }
155166 continue
156167 }
157- m .Fields [i ].ID = int (tmpField [0 ] / 2 )
168+ m .Fields [i ].ID = int (tmpField [0 ] >> 1 )
158169 switch f := m .Fields [i ].Type .(type ) {
159170 case FieldIntFixed :
160171 f .Value , err = decodeFixed (r , f .Length )
@@ -207,12 +218,12 @@ func decodeString(r io.Reader) (string, error) {
207218 if err != nil {
208219 return "" , err
209220 }
210- strBytes := make ([]byte , firstByte [0 ]/ 2 )
221+ strBytes := make ([]byte , firstByte [0 ] >> 1 )
211222 n , err := r .Read (strBytes )
212223 if err != nil {
213224 return "" , err
214225 }
215- if n != int (firstByte [0 ]/ 2 ) {
226+ if n != int (firstByte [0 ] >> 1 ) {
216227 return "" , fmt .Errorf ("only read %d bytes, expected %d" , n , firstByte [0 ]/ 2 )
217228 }
218229 return string (strBytes ), nil
@@ -228,7 +239,7 @@ func decodeFixed(r io.Reader, len int) ([]byte, error) {
228239 return nil , err
229240 }
230241 if tmpInt [0 ]% 2 == 0 {
231- b .WriteByte (tmpInt [0 ] / 2 )
242+ b .WriteByte (tmpInt [0 ] >> 1 )
232243 } else {
233244 tmpInt2 := make ([]byte , 1 )
234245 _ , err := r .Read (tmpInt2 )
0 commit comments