We can not use encoding/binary in hash packages because of import cycles.
So just keep the appendUint and readUint helper functions same as that
in the encoding/binary standard package.
There is no notable performance impacts.
Updates #63719
Change-Id: If47a7faaf9d422d772f32bbe1fa2f2c8a16485f4
GitHub-Last-Rev:
f334fee408eff6869a7cc5f306df525d4d55d2cf
GitHub-Pull-Request: golang/go#63746
Reviewed-on: https://go-review.googlesource.com/c/go/+/537796
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
return nil
}
+// appendUint32 is semantically the same as [binary.BigEndian.AppendUint32]
+// We copied this function because we can not import "encoding/binary" here.
func appendUint32(b []byte, x uint32) []byte {
- a := [4]byte{
- byte(x >> 24),
- byte(x >> 16),
- byte(x >> 8),
+ return append(b,
+ byte(x>>24),
+ byte(x>>16),
+ byte(x>>8),
byte(x),
- }
- return append(b, a[:]...)
+ )
}
+// readUint32 is semantically the same as [binary.BigEndian.Uint32]
+// We copied this function because we can not import "encoding/binary" here.
func readUint32(b []byte) uint32 {
_ = b[3]
return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
return nil
}
+// appendUint32 is semantically the same as [binary.BigEndian.AppendUint32]
+// We copied this function because we can not import "encoding/binary" here.
func appendUint32(b []byte, x uint32) []byte {
- a := [4]byte{
- byte(x >> 24),
- byte(x >> 16),
- byte(x >> 8),
+ return append(b,
+ byte(x>>24),
+ byte(x>>16),
+ byte(x>>8),
byte(x),
- }
- return append(b, a[:]...)
+ )
}
+// readUint32 is semantically the same as [binary.BigEndian.Uint32]
+// We copied this function because we can not import "encoding/binary" here.
func readUint32(b []byte) uint32 {
_ = b[3]
return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
return nil
}
+// appendUint64 is semantically the same as [binary.BigEndian.AppendUint64]
+// We copied this function because we can not import "encoding/binary" here.
func appendUint64(b []byte, x uint64) []byte {
- a := [8]byte{
- byte(x >> 56),
- byte(x >> 48),
- byte(x >> 40),
- byte(x >> 32),
- byte(x >> 24),
- byte(x >> 16),
- byte(x >> 8),
+ return append(b,
+ byte(x>>56),
+ byte(x>>48),
+ byte(x>>40),
+ byte(x>>32),
+ byte(x>>24),
+ byte(x>>16),
+ byte(x>>8),
byte(x),
- }
- return append(b, a[:]...)
+ )
}
+// readUint64 is semantically the same as [binary.BigEndian.Uint64]
+// We copied this function because we can not import "encoding/binary" here.
func readUint64(b []byte) uint64 {
_ = b[7]
return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
return nil
}
+// readUint32 is semantically the same as [binary.BigEndian.Uint32]
+// We copied this function because we can not import "encoding/binary" here.
func readUint32(b []byte) uint32 {
_ = b[3]
return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
}
+// appendUint32 is semantically the same as [binary.BigEndian.AppendUint32]
+// We copied this function because we can not import "encoding/binary" here.
func appendUint32(b []byte, x uint32) []byte {
- a := [4]byte{
- byte(x >> 24),
- byte(x >> 16),
- byte(x >> 8),
+ return append(b,
+ byte(x>>24),
+ byte(x>>16),
+ byte(x>>8),
byte(x),
- }
- return append(b, a[:]...)
+ )
}
+// appendUint64 is semantically the same as [binary.BigEndian.AppendUint64]
+// We copied this function because we can not import "encoding/binary" here.
func appendUint64(b []byte, x uint64) []byte {
- a := [8]byte{
- byte(x >> 56),
- byte(x >> 48),
- byte(x >> 40),
- byte(x >> 32),
- byte(x >> 24),
- byte(x >> 16),
- byte(x >> 8),
+ return append(b,
+ byte(x>>56),
+ byte(x>>48),
+ byte(x>>40),
+ byte(x>>32),
+ byte(x>>24),
+ byte(x>>16),
+ byte(x>>8),
byte(x),
- }
- return append(b, a[:]...)
+ )
}
+// readUint64 is semantically the same as [binary.BigEndian.Uint64]
+// We copied this function because we can not import "encoding/binary" here.
func readUint64(b []byte) uint64 {
_ = b[7]
return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |