implementing codec

This commit is contained in:
James Cor
2023-01-24 23:22:26 -08:00
parent 4dfb647d2f
commit d438c6702a
3 changed files with 26 additions and 8 deletions
+9 -4
View File
@@ -599,10 +599,6 @@ func compareAddr(l, r hash.Hash) int {
return l.Compare(r)
}
func compareZAddr(l, r [zAddrSize]byte) int {
return bytes.Compare(l[:], r[:])
}
func writeRaw(buf, val []byte) {
expectSize(buf, ByteSize(len(val)))
copy(buf, val)
@@ -629,8 +625,17 @@ func stringFromBytes(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
func compareZAddr(l, r [zAddrSize]byte) int {
return bytes.Compare(l[:], r[:])
}
func readZAddr(val []byte) (res [zAddrSize]byte) {
expectSize(val, zAddrSize)
copy(res[:zAddrSize], val[:zAddrSize])
return
}
func writeZAddr(buf []byte, v [zAddrSize]byte) {
expectSize(buf, zAddrSize)
copy(buf, v[:zAddrSize])
}
+8 -4
View File
@@ -15,7 +15,6 @@
package val
import (
"github.com/dolthub/go-mysql-server/sql/types"
"math"
"testing"
"time"
@@ -243,6 +242,10 @@ func TestCompare(t *testing.T) {
},
// z-address
{
typ: Type{Enc: StringEnc},
l: encZAddr([zAddrSize]byte{}),
r: encZAddr([zAddrSize]byte{}),
cmp: 0,
},
}
@@ -301,9 +304,10 @@ func encStr(s string) []byte {
return buf
}
func encZAddr(g types.GeometryValue) []byte {
buf := ZAddr(g)
return buf[:]
func encZAddr(z [zAddrSize]byte) []byte {
buf := make([]byte, zAddrSize)
writeZAddr(buf, z)
return buf
}
func encYear(y int16) []byte {
+9
View File
@@ -366,3 +366,12 @@ func (tb *TupleBuilder) ensureCapacity(sz ByteSize) {
}
}
}
// PutZAddr writes a bounding box to the ith field of the Tuple being built.
func (tb *TupleBuilder) PutZAddr(i int, v [zAddrSize]byte) {
tb.Desc.expectEncoding(i, ZAddrEnc)
tb.ensureCapacity(zAddrSize)
tb.fields[i] = tb.buf[tb.pos : tb.pos+zAddrSize]
writeZAddr(tb.fields[i], v)
tb.pos += zAddrSize
}