@@ -55,6 +55,11 @@ func (r *BinaryReader) Len() uint32 {
5555 return uint32 (len (r .buf )) - r .pos
5656}
5757
58+ // SetLen sets the remaining length of the underlying buffer.
59+ func (r * BinaryReader ) SetLen (n uint32 ) {
60+ r .buf = r .buf [: r .pos + n : r .pos + n ]
61+ }
62+
5863// EOF returns true if we reached the end-of-file.
5964func (r * BinaryReader ) EOF () bool {
6065 return r .eof
@@ -110,6 +115,18 @@ func (r *BinaryReader) ReadUint16() uint16 {
110115 return r .Endianness .Uint16 (b )
111116}
112117
118+ // ReadUint24 reads a uint24 into a uint32.
119+ func (r * BinaryReader ) ReadUint24 () uint32 {
120+ b := r .ReadBytes (3 )
121+ if b == nil {
122+ return 0
123+ } else if r .Endianness == binary .LittleEndian {
124+ return uint32 (b [0 ]) | uint32 (b [1 ])<< 8 | uint32 (b [2 ])<< 16
125+ } else {
126+ return uint32 (b [2 ]) | uint32 (b [1 ])<< 8 | uint32 (b [0 ])<< 16
127+ }
128+ }
129+
113130// ReadUint32 reads a uint32.
114131func (r * BinaryReader ) ReadUint32 () uint32 {
115132 b := r .ReadBytes (4 )
@@ -128,22 +145,27 @@ func (r *BinaryReader) ReadUint64() uint64 {
128145 return r .Endianness .Uint64 (b )
129146}
130147
131- // ReadInt8 reads a int8.
148+ // ReadInt8 reads an int8.
132149func (r * BinaryReader ) ReadInt8 () int8 {
133150 return int8 (r .ReadByte ())
134151}
135152
136- // ReadInt16 reads a int16.
153+ // ReadInt16 reads an int16.
137154func (r * BinaryReader ) ReadInt16 () int16 {
138155 return int16 (r .ReadUint16 ())
139156}
140157
141- // ReadInt32 reads a int32.
158+ // ReadInt24 reads a int24 into an int32.
159+ func (r * BinaryReader ) ReadInt24 () int32 {
160+ return int32 (r .ReadUint24 ())
161+ }
162+
163+ // ReadInt32 reads an int32.
142164func (r * BinaryReader ) ReadInt32 () int32 {
143165 return int32 (r .ReadUint32 ())
144166}
145167
146- // ReadInt64 reads a int64.
168+ // ReadInt64 reads an int64.
147169func (r * BinaryReader ) ReadInt64 () int64 {
148170 return int64 (r .ReadUint64 ())
149171}
0 commit comments