I have a structure like this:
package example
import (
"encoding/binary"
)
const NodeKeySize = 8
var endian = binary.LittleEndian
type Node []byte
func (n Node) PairInsertAt(at uint8, key uint64, value uint64) {
}
func (n Node) PairAt(at uint8) ([]byte, uint64, uint64, bool) {
return nil, endian.Uint64(section), endian.Uint64(section[NodeKeySize:]), true
}
I want to make a variation of this in 32bit but still retain much of the logic. For the example above, it would become like the following:
package example
import (
"encoding/binary"
)
const NodeKeySize = 4
var endian = binary.LittleEndian
type Node []byte
func (n Node) PairInsertAt(at uint8, key uint32, value uint32) {
}
func (n Node) PairAt(at uint8) ([]byte, uint32, uint32, bool) {
return nil, endian.Uint64(section), endian.Uint64(section[NodeKeySize:]), true
}
Is there an easy way to do this without changing much of the internal logic such as that if I modify the 64bit version, the 32bit version automatically adapts?