mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 10:37:46 +00:00
machine: use new internal/binary package
The encoding/binary package in Go 1.23 imports the slices package, which results in circular import when imported from the machine package. Therefore, encoding/binary cannot be used in the machine package. This commit fixes that by introducing a new internal/binary package that is just plain Go code without dependencies. It can be safely used anywhere (including the runtime if needed).
This commit is contained in:
committed by
Ron Evans
parent
868262f4a7
commit
1270a50104
@@ -236,6 +236,7 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
|
||||
"device/": false,
|
||||
"examples/": false,
|
||||
"internal/": true,
|
||||
"internal/binary/": false,
|
||||
"internal/bytealg/": false,
|
||||
"internal/fuzz/": false,
|
||||
"internal/reflectlite/": false,
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Package binary is a lightweight replacement package for encoding/binary.
|
||||
package binary
|
||||
|
||||
// This file contains small helper functions for working with binary data.
|
||||
|
||||
var LittleEndian = littleEndian{}
|
||||
|
||||
type littleEndian struct{}
|
||||
|
||||
// Encode data like encoding/binary.LittleEndian.Uint16.
|
||||
func (littleEndian) Uint16(b []byte) uint16 {
|
||||
return uint16(b[0]) | uint16(b[1])<<8
|
||||
}
|
||||
|
||||
// Store data like binary.LittleEndian.PutUint16.
|
||||
func (littleEndian) PutUint16(b []byte, v uint16) {
|
||||
b[0] = byte(v)
|
||||
b[1] = byte(v >> 8)
|
||||
}
|
||||
|
||||
// Append data like binary.LittleEndian.AppendUint16.
|
||||
func (littleEndian) AppendUint16(b []byte, v uint16) []byte {
|
||||
return append(b,
|
||||
byte(v),
|
||||
byte(v>>8),
|
||||
)
|
||||
}
|
||||
|
||||
// Encode data like encoding/binary.LittleEndian.Uint32.
|
||||
func (littleEndian) Uint32(b []byte) uint32 {
|
||||
return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
|
||||
}
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"bytes"
|
||||
"device/arm"
|
||||
"device/sam"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"internal/binary"
|
||||
"runtime/interrupt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"bytes"
|
||||
"device/arm"
|
||||
"device/sam"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"internal/binary"
|
||||
"runtime/interrupt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ package machine
|
||||
import (
|
||||
"bytes"
|
||||
"device/nrf"
|
||||
"encoding/binary"
|
||||
"internal/binary"
|
||||
"runtime/interrupt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@@ -6,8 +6,8 @@ package machine
|
||||
|
||||
import (
|
||||
"device/stm32"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"internal/binary"
|
||||
"math/bits"
|
||||
"runtime/interrupt"
|
||||
"runtime/volatile"
|
||||
|
||||
@@ -4,8 +4,8 @@ package machine
|
||||
|
||||
import (
|
||||
"device/stm32"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"internal/binary"
|
||||
"runtime/interrupt"
|
||||
"runtime/volatile"
|
||||
"unsafe"
|
||||
|
||||
@@ -6,8 +6,8 @@ package machine
|
||||
|
||||
import (
|
||||
"device/stm32"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"internal/binary"
|
||||
"math/bits"
|
||||
"runtime/interrupt"
|
||||
"runtime/volatile"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package descriptor
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"internal/binary"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package descriptor
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"internal/binary"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package descriptor
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"internal/binary"
|
||||
)
|
||||
|
||||
var endpointEP1IN = [endpointTypeLen]byte{
|
||||
|
||||
@@ -2,8 +2,8 @@ package descriptor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"internal/binary"
|
||||
)
|
||||
|
||||
var configurationCDCHID = [configurationTypeLen]byte{
|
||||
|
||||
Reference in New Issue
Block a user