@@ -15,6 +15,7 @@ package fnv
15
15
import (
16
16
"errors"
17
17
"hash"
18
+ "internal/byteorder"
18
19
"math/bits"
19
20
)
20
21
@@ -225,44 +226,44 @@ const (
225
226
func (s * sum32 ) MarshalBinary () ([]byte , error ) {
226
227
b := make ([]byte , 0 , marshaledSize32 )
227
228
b = append (b , magic32 ... )
228
- b = appendUint32 (b , uint32 (* s ))
229
+ b = byteorder . BeAppendUint32 (b , uint32 (* s ))
229
230
return b , nil
230
231
}
231
232
232
233
func (s * sum32a ) MarshalBinary () ([]byte , error ) {
233
234
b := make ([]byte , 0 , marshaledSize32 )
234
235
b = append (b , magic32a ... )
235
- b = appendUint32 (b , uint32 (* s ))
236
+ b = byteorder . BeAppendUint32 (b , uint32 (* s ))
236
237
return b , nil
237
238
}
238
239
239
240
func (s * sum64 ) MarshalBinary () ([]byte , error ) {
240
241
b := make ([]byte , 0 , marshaledSize64 )
241
242
b = append (b , magic64 ... )
242
- b = appendUint64 (b , uint64 (* s ))
243
+ b = byteorder . BeAppendUint64 (b , uint64 (* s ))
243
244
return b , nil
244
245
}
245
246
246
247
func (s * sum64a ) MarshalBinary () ([]byte , error ) {
247
248
b := make ([]byte , 0 , marshaledSize64 )
248
249
b = append (b , magic64a ... )
249
- b = appendUint64 (b , uint64 (* s ))
250
+ b = byteorder . BeAppendUint64 (b , uint64 (* s ))
250
251
return b , nil
251
252
}
252
253
253
254
func (s * sum128 ) MarshalBinary () ([]byte , error ) {
254
255
b := make ([]byte , 0 , marshaledSize128 )
255
256
b = append (b , magic128 ... )
256
- b = appendUint64 (b , s [0 ])
257
- b = appendUint64 (b , s [1 ])
257
+ b = byteorder . BeAppendUint64 (b , s [0 ])
258
+ b = byteorder . BeAppendUint64 (b , s [1 ])
258
259
return b , nil
259
260
}
260
261
261
262
func (s * sum128a ) MarshalBinary () ([]byte , error ) {
262
263
b := make ([]byte , 0 , marshaledSize128 )
263
264
b = append (b , magic128a ... )
264
- b = appendUint64 (b , s [0 ])
265
- b = appendUint64 (b , s [1 ])
265
+ b = byteorder . BeAppendUint64 (b , s [0 ])
266
+ b = byteorder . BeAppendUint64 (b , s [1 ])
266
267
return b , nil
267
268
}
268
269
@@ -273,7 +274,7 @@ func (s *sum32) UnmarshalBinary(b []byte) error {
273
274
if len (b ) != marshaledSize32 {
274
275
return errors .New ("hash/fnv: invalid hash state size" )
275
276
}
276
- * s = sum32 (readUint32 (b [4 :]))
277
+ * s = sum32 (byteorder . BeUint32 (b [4 :]))
277
278
return nil
278
279
}
279
280
@@ -284,7 +285,7 @@ func (s *sum32a) UnmarshalBinary(b []byte) error {
284
285
if len (b ) != marshaledSize32 {
285
286
return errors .New ("hash/fnv: invalid hash state size" )
286
287
}
287
- * s = sum32a (readUint32 (b [4 :]))
288
+ * s = sum32a (byteorder . BeUint32 (b [4 :]))
288
289
return nil
289
290
}
290
291
@@ -295,7 +296,7 @@ func (s *sum64) UnmarshalBinary(b []byte) error {
295
296
if len (b ) != marshaledSize64 {
296
297
return errors .New ("hash/fnv: invalid hash state size" )
297
298
}
298
- * s = sum64 (readUint64 (b [4 :]))
299
+ * s = sum64 (byteorder . BeUint64 (b [4 :]))
299
300
return nil
300
301
}
301
302
@@ -306,7 +307,7 @@ func (s *sum64a) UnmarshalBinary(b []byte) error {
306
307
if len (b ) != marshaledSize64 {
307
308
return errors .New ("hash/fnv: invalid hash state size" )
308
309
}
309
- * s = sum64a (readUint64 (b [4 :]))
310
+ * s = sum64a (byteorder . BeUint64 (b [4 :]))
310
311
return nil
311
312
}
312
313
@@ -317,8 +318,8 @@ func (s *sum128) UnmarshalBinary(b []byte) error {
317
318
if len (b ) != marshaledSize128 {
318
319
return errors .New ("hash/fnv: invalid hash state size" )
319
320
}
320
- s [0 ] = readUint64 (b [4 :])
321
- s [1 ] = readUint64 (b [12 :])
321
+ s [0 ] = byteorder . BeUint64 (b [4 :])
322
+ s [1 ] = byteorder . BeUint64 (b [12 :])
322
323
return nil
323
324
}
324
325
@@ -329,48 +330,7 @@ func (s *sum128a) UnmarshalBinary(b []byte) error {
329
330
if len (b ) != marshaledSize128 {
330
331
return errors .New ("hash/fnv: invalid hash state size" )
331
332
}
332
- s [0 ] = readUint64 (b [4 :])
333
- s [1 ] = readUint64 (b [12 :])
333
+ s [0 ] = byteorder . BeUint64 (b [4 :])
334
+ s [1 ] = byteorder . BeUint64 (b [12 :])
334
335
return nil
335
336
}
336
-
337
- // readUint32 is semantically the same as [binary.BigEndian.Uint32]
338
- // We copied this function because we can not import "encoding/binary" here.
339
- func readUint32 (b []byte ) uint32 {
340
- _ = b [3 ]
341
- return uint32 (b [3 ]) | uint32 (b [2 ])<< 8 | uint32 (b [1 ])<< 16 | uint32 (b [0 ])<< 24
342
- }
343
-
344
- // appendUint32 is semantically the same as [binary.BigEndian.AppendUint32]
345
- // We copied this function because we can not import "encoding/binary" here.
346
- func appendUint32 (b []byte , x uint32 ) []byte {
347
- return append (b ,
348
- byte (x >> 24 ),
349
- byte (x >> 16 ),
350
- byte (x >> 8 ),
351
- byte (x ),
352
- )
353
- }
354
-
355
- // appendUint64 is semantically the same as [binary.BigEndian.AppendUint64]
356
- // We copied this function because we can not import "encoding/binary" here.
357
- func appendUint64 (b []byte , x uint64 ) []byte {
358
- return append (b ,
359
- byte (x >> 56 ),
360
- byte (x >> 48 ),
361
- byte (x >> 40 ),
362
- byte (x >> 32 ),
363
- byte (x >> 24 ),
364
- byte (x >> 16 ),
365
- byte (x >> 8 ),
366
- byte (x ),
367
- )
368
- }
369
-
370
- // readUint64 is semantically the same as [binary.BigEndian.Uint64]
371
- // We copied this function because we can not import "encoding/binary" here.
372
- func readUint64 (b []byte ) uint64 {
373
- _ = b [7 ]
374
- return uint64 (b [7 ]) | uint64 (b [6 ])<< 8 | uint64 (b [5 ])<< 16 | uint64 (b [4 ])<< 24 |
375
- uint64 (b [3 ])<< 32 | uint64 (b [2 ])<< 40 | uint64 (b [1 ])<< 48 | uint64 (b [0 ])<< 56
376
- }
0 commit comments