made codec functions pkg private

This commit is contained in:
Andy Arthur
2022-02-09 17:05:25 -08:00
parent 9a2dae47e6
commit 553762ee14
6 changed files with 95 additions and 95 deletions

View File

@@ -125,7 +125,7 @@ func sizeFromType(t Type) (ByteSize, bool) {
}
}
func ReadBool(val []byte) bool {
func readBool(val []byte) bool {
expectSize(val, int8Size)
return val[0] == 1
}
@@ -150,12 +150,12 @@ func compareBool(l, r bool) int {
return 1
}
func ReadInt8(val []byte) int8 {
func readInt8(val []byte) int8 {
expectSize(val, int8Size)
return int8(val[0])
}
func WriteInt8(buf []byte, val int8) {
func writeInt8(buf []byte, val int8) {
expectSize(buf, int8Size)
buf[0] = byte(val)
}
@@ -170,12 +170,12 @@ func compareInt8(l, r int8) int {
}
}
func ReadUint8(val []byte) uint8 {
func readUint8(val []byte) uint8 {
expectSize(val, uint8Size)
return val[0]
}
func WriteUint8(buf []byte, val uint8) {
func writeUint8(buf []byte, val uint8) {
expectSize(buf, uint8Size)
buf[0] = byte(val)
}
@@ -190,12 +190,12 @@ func compareUint8(l, r uint8) int {
}
}
func ReadInt16(val []byte) int16 {
func readInt16(val []byte) int16 {
expectSize(val, int16Size)
return int16(binary.LittleEndian.Uint16(val))
}
func WriteInt16(buf []byte, val int16) {
func writeInt16(buf []byte, val int16) {
expectSize(buf, int16Size)
binary.LittleEndian.PutUint16(buf, uint16(val))
}
@@ -210,12 +210,12 @@ func compareInt16(l, r int16) int {
}
}
func ReadUint16(val []byte) uint16 {
func readUint16(val []byte) uint16 {
expectSize(val, uint16Size)
return binary.LittleEndian.Uint16(val)
}
func WriteUint16(buf []byte, val uint16) {
func writeUint16(buf []byte, val uint16) {
expectSize(buf, uint16Size)
binary.LittleEndian.PutUint16(buf, val)
}
@@ -230,12 +230,12 @@ func compareUint16(l, r uint16) int {
}
}
func ReadInt32(val []byte) int32 {
func readInt32(val []byte) int32 {
expectSize(val, int32Size)
return int32(binary.LittleEndian.Uint32(val))
}
func WriteInt32(buf []byte, val int32) {
func writeInt32(buf []byte, val int32) {
expectSize(buf, int32Size)
binary.LittleEndian.PutUint32(buf, uint32(val))
}
@@ -250,12 +250,12 @@ func compareInt32(l, r int32) int {
}
}
func ReadUint32(val []byte) uint32 {
func readUint32(val []byte) uint32 {
expectSize(val, uint32Size)
return binary.LittleEndian.Uint32(val)
}
func WriteUint32(buf []byte, val uint32) {
func writeUint32(buf []byte, val uint32) {
expectSize(buf, uint32Size)
binary.LittleEndian.PutUint32(buf, val)
}
@@ -270,12 +270,12 @@ func compareUint32(l, r uint32) int {
}
}
func ReadInt64(val []byte) int64 {
func readInt64(val []byte) int64 {
expectSize(val, int64Size)
return int64(binary.LittleEndian.Uint64(val))
}
func WriteInt64(buf []byte, val int64) {
func writeInt64(buf []byte, val int64) {
expectSize(buf, int64Size)
binary.LittleEndian.PutUint64(buf, uint64(val))
}
@@ -290,12 +290,12 @@ func compareInt64(l, r int64) int {
}
}
func ReadUint64(val []byte) uint64 {
func readUint64(val []byte) uint64 {
expectSize(val, uint64Size)
return binary.LittleEndian.Uint64(val)
}
func WriteUint64(buf []byte, val uint64) {
func writeUint64(buf []byte, val uint64) {
expectSize(buf, uint64Size)
binary.LittleEndian.PutUint64(buf, val)
}
@@ -310,12 +310,12 @@ func compareUint64(l, r uint64) int {
}
}
func ReadFloat32(val []byte) float32 {
func readFloat32(val []byte) float32 {
expectSize(val, float32Size)
return math.Float32frombits(ReadUint32(val))
return math.Float32frombits(readUint32(val))
}
func WriteFloat32(buf []byte, val float32) {
func writeFloat32(buf []byte, val float32) {
expectSize(buf, float32Size)
binary.LittleEndian.PutUint32(buf, math.Float32bits(val))
}
@@ -330,12 +330,12 @@ func compareFloat32(l, r float32) int {
}
}
func ReadFloat64(val []byte) float64 {
func readFloat64(val []byte) float64 {
expectSize(val, float64Size)
return math.Float64frombits(ReadUint64(val))
return math.Float64frombits(readUint64(val))
}
func WriteFloat64(buf []byte, val float64) {
func writeFloat64(buf []byte, val float64) {
expectSize(buf, float64Size)
binary.LittleEndian.PutUint64(buf, math.Float64bits(val))
}
@@ -350,7 +350,7 @@ func compareFloat64(l, r float64) int {
}
}
func ReadTimestamp(buf []byte) (t time.Time) {
func readTimestamp(buf []byte) (t time.Time) {
expectSize(buf, timestampSize)
if err := t.UnmarshalBinary(buf); err != nil {
panic(err)
@@ -358,7 +358,7 @@ func ReadTimestamp(buf []byte) (t time.Time) {
return t
}
func WriteTimestamp(buf []byte, val time.Time) {
func writeTimestamp(buf []byte, val time.Time) {
expectSize(buf, timestampSize)
// todo(andy): fix allocation here
m, _ := val.MarshalBinary()
@@ -375,7 +375,7 @@ func compareTimestamp(l, r time.Time) int {
}
}
func ReadString(val []byte) string {
func readString(val []byte) string {
// todo(andy): fix allocation
return string(val)
}
@@ -420,36 +420,36 @@ func compare(typ Type, left, right []byte) int {
switch typ.Enc {
case Int8Enc:
return compareInt8(ReadInt8(left), ReadInt8(right))
return compareInt8(readInt8(left), readInt8(right))
case Uint8Enc:
return compareUint8(ReadUint8(left), ReadUint8(right))
return compareUint8(readUint8(left), readUint8(right))
case Int16Enc:
return compareInt16(ReadInt16(left), ReadInt16(right))
return compareInt16(readInt16(left), readInt16(right))
case Uint16Enc:
return compareUint16(ReadUint16(left), ReadUint16(right))
return compareUint16(readUint16(left), readUint16(right))
case Int32Enc:
return compareInt32(ReadInt32(left), ReadInt32(right))
return compareInt32(readInt32(left), readInt32(right))
case Uint32Enc:
return compareUint32(ReadUint32(left), ReadUint32(right))
return compareUint32(readUint32(left), readUint32(right))
case Int64Enc:
return compareInt64(ReadInt64(left), ReadInt64(right))
return compareInt64(readInt64(left), readInt64(right))
case Uint64Enc:
return compareUint64(ReadUint64(left), ReadUint64(right))
return compareUint64(readUint64(left), readUint64(right))
case Float32Enc:
return compareFloat32(ReadFloat32(left), ReadFloat32(right))
return compareFloat32(readFloat32(left), readFloat32(right))
case Float64Enc:
return compareFloat64(ReadFloat64(left), ReadFloat64(right))
return compareFloat64(readFloat64(left), readFloat64(right))
case YearEnc:
return compareInt16(ReadInt16(left), ReadInt16(right))
return compareInt16(readInt16(left), readInt16(right))
case DateEnc, DatetimeEnc, TimestampEnc:
return compareTimestamp(ReadTimestamp(left), ReadTimestamp(right))
return compareTimestamp(readTimestamp(left), readTimestamp(right))
case TimeEnc:
panic("unimplemented")
case DecimalEnc:
// todo(andy): temporary Decimal implementation
fallthrough
case StringEnc:
return compareString(ReadString(left), ReadString(right))
return compareString(readString(left), readString(right))
case BytesEnc:
return compareBytes(readBytes(left), readBytes(right))
default:

View File

@@ -116,19 +116,19 @@ func TestCompare(t *testing.T) {
func encInt(i int64) []byte {
buf := make([]byte, 8)
WriteInt64(buf, i)
writeInt64(buf, i)
return buf
}
func encUint(u uint64) []byte {
buf := make([]byte, 8)
WriteUint64(buf, u)
writeUint64(buf, u)
return buf
}
func encFloat(f float64) []byte {
buf := make([]byte, 8)
WriteFloat64(buf, f)
writeFloat64(buf, f)
return buf
}
@@ -156,7 +156,7 @@ func roundTripBools(t *testing.T) {
integers := []bool{true, false}
for _, exp := range integers {
writeBool(buf, exp)
assert.Equal(t, exp, ReadBool(buf))
assert.Equal(t, exp, readBool(buf))
zero(buf)
}
}
@@ -166,8 +166,8 @@ func roundTripInts(t *testing.T) {
integers := []int64{-1, 0, -1, math.MaxInt8, math.MinInt8}
for _, value := range integers {
exp := int8(value)
WriteInt8(buf, exp)
assert.Equal(t, exp, ReadInt8(buf))
writeInt8(buf, exp)
assert.Equal(t, exp, readInt8(buf))
zero(buf)
}
@@ -175,8 +175,8 @@ func roundTripInts(t *testing.T) {
integers = append(integers, math.MaxInt16, math.MaxInt16)
for _, value := range integers {
exp := int16(value)
WriteInt16(buf, exp)
assert.Equal(t, exp, ReadInt16(buf))
writeInt16(buf, exp)
assert.Equal(t, exp, readInt16(buf))
zero(buf)
}
@@ -184,8 +184,8 @@ func roundTripInts(t *testing.T) {
integers = append(integers, math.MaxInt32, math.MaxInt32)
for _, value := range integers {
exp := int32(value)
WriteInt32(buf, exp)
assert.Equal(t, exp, ReadInt32(buf))
writeInt32(buf, exp)
assert.Equal(t, exp, readInt32(buf))
zero(buf)
}
@@ -193,8 +193,8 @@ func roundTripInts(t *testing.T) {
integers = append(integers, math.MaxInt64, math.MaxInt64)
for _, value := range integers {
exp := int64(value)
WriteInt64(buf, exp)
assert.Equal(t, exp, ReadInt64(buf))
writeInt64(buf, exp)
assert.Equal(t, exp, readInt64(buf))
zero(buf)
}
}
@@ -204,8 +204,8 @@ func roundTripUints(t *testing.T) {
uintegers := []uint64{0, 1, math.MaxUint8}
for _, value := range uintegers {
exp := uint8(value)
WriteUint8(buf, exp)
assert.Equal(t, exp, ReadUint8(buf))
writeUint8(buf, exp)
assert.Equal(t, exp, readUint8(buf))
zero(buf)
}
@@ -213,8 +213,8 @@ func roundTripUints(t *testing.T) {
uintegers = append(uintegers, math.MaxUint16)
for _, value := range uintegers {
exp := uint16(value)
WriteUint16(buf, exp)
assert.Equal(t, exp, ReadUint16(buf))
writeUint16(buf, exp)
assert.Equal(t, exp, readUint16(buf))
zero(buf)
}
@@ -222,8 +222,8 @@ func roundTripUints(t *testing.T) {
uintegers = append(uintegers, math.MaxUint32)
for _, value := range uintegers {
exp := uint32(value)
WriteUint32(buf, exp)
assert.Equal(t, exp, ReadUint32(buf))
writeUint32(buf, exp)
assert.Equal(t, exp, readUint32(buf))
zero(buf)
}
@@ -231,8 +231,8 @@ func roundTripUints(t *testing.T) {
uintegers = append(uintegers, math.MaxUint64)
for _, value := range uintegers {
exp := uint64(value)
WriteUint64(buf, exp)
assert.Equal(t, exp, ReadUint64(buf))
writeUint64(buf, exp)
assert.Equal(t, exp, readUint64(buf))
zero(buf)
}
}
@@ -242,8 +242,8 @@ func roundTripFloats(t *testing.T) {
floats := []float64{-1, 0, 1, math.MaxFloat32, math.SmallestNonzeroFloat32}
for _, value := range floats {
exp := float32(value)
WriteFloat32(buf, exp)
assert.Equal(t, exp, ReadFloat32(buf))
writeFloat32(buf, exp)
assert.Equal(t, exp, readFloat32(buf))
zero(buf)
}
@@ -251,8 +251,8 @@ func roundTripFloats(t *testing.T) {
floats = append(floats, math.MaxFloat64, math.SmallestNonzeroFloat64)
for _, value := range floats {
exp := float64(value)
WriteFloat64(buf, exp)
assert.Equal(t, exp, ReadFloat64(buf))
writeFloat64(buf, exp)
assert.Equal(t, exp, readFloat64(buf))
zero(buf)
}
}

View File

@@ -54,7 +54,7 @@ func (os Offsets) getOffset(i int) ByteSize {
return 0
}
start := (i - 1) * 2
off := ReadUint16(os[start : start+2])
off := readUint16(os[start : start+2])
return ByteSize(off)
}
@@ -64,7 +64,7 @@ func (os Offsets) Put(i int, off ByteSize) {
return
}
start := (i - 1) * 2
WriteUint16(os[start:start+2], uint16(off))
writeUint16(os[start:start+2], uint16(off))
}
// isLastIndex returns true if |i| is the last index in |sl|.

View File

@@ -157,7 +157,7 @@ func (tup Tuple) Count() int {
func (tup Tuple) fieldCount() int {
sl := tup[tup.size()-numFieldsSize:]
return int(ReadUint16(sl))
return int(readUint16(sl))
}
func (tup Tuple) valueCount() int {
@@ -192,5 +192,5 @@ func sizeOf(val []byte) ByteSize {
func writeFieldCount(tup Tuple, count int) {
sl := tup[len(tup)-int(numFieldsSize):]
WriteUint16(sl, uint16(count))
writeUint16(sl, uint16(count))
}

View File

@@ -86,7 +86,7 @@ func (tb *TupleBuilder) PutBool(i int, v bool) {
func (tb *TupleBuilder) PutInt8(i int, v int8) {
tb.Desc.expectEncoding(i, Int8Enc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+int8Size]
WriteInt8(tb.fields[i], v)
writeInt8(tb.fields[i], v)
tb.pos += int8Size
}
@@ -94,7 +94,7 @@ func (tb *TupleBuilder) PutInt8(i int, v int8) {
func (tb *TupleBuilder) PutUint8(i int, v uint8) {
tb.Desc.expectEncoding(i, Uint8Enc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+uint8Size]
WriteUint8(tb.fields[i], v)
writeUint8(tb.fields[i], v)
tb.pos += uint8Size
}
@@ -102,7 +102,7 @@ func (tb *TupleBuilder) PutUint8(i int, v uint8) {
func (tb *TupleBuilder) PutInt16(i int, v int16) {
tb.Desc.expectEncoding(i, Int16Enc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+int16Size]
WriteInt16(tb.fields[i], v)
writeInt16(tb.fields[i], v)
tb.pos += int16Size
}
@@ -110,7 +110,7 @@ func (tb *TupleBuilder) PutInt16(i int, v int16) {
func (tb *TupleBuilder) PutUint16(i int, v uint16) {
tb.Desc.expectEncoding(i, Uint16Enc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+uint16Size]
WriteUint16(tb.fields[i], v)
writeUint16(tb.fields[i], v)
tb.pos += uint16Size
}
@@ -118,7 +118,7 @@ func (tb *TupleBuilder) PutUint16(i int, v uint16) {
func (tb *TupleBuilder) PutInt32(i int, v int32) {
tb.Desc.expectEncoding(i, Int32Enc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+int32Size]
WriteInt32(tb.fields[i], v)
writeInt32(tb.fields[i], v)
tb.pos += int32Size
}
@@ -126,7 +126,7 @@ func (tb *TupleBuilder) PutInt32(i int, v int32) {
func (tb *TupleBuilder) PutUint32(i int, v uint32) {
tb.Desc.expectEncoding(i, Uint32Enc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+uint32Size]
WriteUint32(tb.fields[i], v)
writeUint32(tb.fields[i], v)
tb.pos += uint32Size
}
@@ -134,7 +134,7 @@ func (tb *TupleBuilder) PutUint32(i int, v uint32) {
func (tb *TupleBuilder) PutInt64(i int, v int64) {
tb.Desc.expectEncoding(i, Int64Enc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+int64Size]
WriteInt64(tb.fields[i], v)
writeInt64(tb.fields[i], v)
tb.pos += int64Size
}
@@ -142,7 +142,7 @@ func (tb *TupleBuilder) PutInt64(i int, v int64) {
func (tb *TupleBuilder) PutUint64(i int, v uint64) {
tb.Desc.expectEncoding(i, Uint64Enc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+uint64Size]
WriteUint64(tb.fields[i], v)
writeUint64(tb.fields[i], v)
tb.pos += uint64Size
}
@@ -150,7 +150,7 @@ func (tb *TupleBuilder) PutUint64(i int, v uint64) {
func (tb *TupleBuilder) PutFloat32(i int, v float32) {
tb.Desc.expectEncoding(i, Float32Enc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+float32Size]
WriteFloat32(tb.fields[i], v)
writeFloat32(tb.fields[i], v)
tb.pos += float32Size
}
@@ -158,14 +158,14 @@ func (tb *TupleBuilder) PutFloat32(i int, v float32) {
func (tb *TupleBuilder) PutFloat64(i int, v float64) {
tb.Desc.expectEncoding(i, Float64Enc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+float64Size]
WriteFloat64(tb.fields[i], v)
writeFloat64(tb.fields[i], v)
tb.pos += float64Size
}
func (tb *TupleBuilder) PutTimestamp(i int, v time.Time) {
tb.Desc.expectEncoding(i, DateEnc, DatetimeEnc, TimestampEnc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+timestampSize]
WriteTimestamp(tb.fields[i], v)
writeTimestamp(tb.fields[i], v)
tb.pos += timestampSize
}
@@ -183,7 +183,7 @@ func (tb *TupleBuilder) PutYear(i int, v int16) {
// todo(andy): yearSize, etc?
tb.Desc.expectEncoding(i, YearEnc)
tb.fields[i] = tb.buf[tb.pos : tb.pos+int16Size]
WriteInt16(tb.fields[i], v)
writeInt16(tb.fields[i], v)
tb.pos += int16Size
}

View File

@@ -95,7 +95,7 @@ func (td TupleDesc) GetBool(i int, tup Tuple) (v bool, ok bool) {
td.expectEncoding(i, Int8Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadBool(b), true
v, ok = readBool(b), true
}
return
}
@@ -106,7 +106,7 @@ func (td TupleDesc) GetInt8(i int, tup Tuple) (v int8, ok bool) {
td.expectEncoding(i, Int8Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadInt8(b), true
v, ok = readInt8(b), true
}
return
}
@@ -117,7 +117,7 @@ func (td TupleDesc) GetUint8(i int, tup Tuple) (v uint8, ok bool) {
td.expectEncoding(i, Uint8Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadUint8(b), true
v, ok = readUint8(b), true
}
return
}
@@ -128,7 +128,7 @@ func (td TupleDesc) GetInt16(i int, tup Tuple) (v int16, ok bool) {
td.expectEncoding(i, Int16Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadInt16(b), true
v, ok = readInt16(b), true
}
return
}
@@ -139,7 +139,7 @@ func (td TupleDesc) GetUint16(i int, tup Tuple) (v uint16, ok bool) {
td.expectEncoding(i, Uint16Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadUint16(b), true
v, ok = readUint16(b), true
}
return
}
@@ -150,7 +150,7 @@ func (td TupleDesc) GetInt32(i int, tup Tuple) (v int32, ok bool) {
td.expectEncoding(i, Int32Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadInt32(b), true
v, ok = readInt32(b), true
}
return
}
@@ -161,7 +161,7 @@ func (td TupleDesc) GetUint32(i int, tup Tuple) (v uint32, ok bool) {
td.expectEncoding(i, Uint32Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadUint32(b), true
v, ok = readUint32(b), true
}
return
}
@@ -172,7 +172,7 @@ func (td TupleDesc) GetInt64(i int, tup Tuple) (v int64, ok bool) {
td.expectEncoding(i, Int64Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadInt64(b), true
v, ok = readInt64(b), true
}
return
}
@@ -183,7 +183,7 @@ func (td TupleDesc) GetUint64(i int, tup Tuple) (v uint64, ok bool) {
td.expectEncoding(i, Uint64Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadUint64(b), true
v, ok = readUint64(b), true
}
return
}
@@ -194,7 +194,7 @@ func (td TupleDesc) GetFloat32(i int, tup Tuple) (v float32, ok bool) {
td.expectEncoding(i, Float32Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadFloat32(b), true
v, ok = readFloat32(b), true
}
return
}
@@ -205,7 +205,7 @@ func (td TupleDesc) GetFloat64(i int, tup Tuple) (v float64, ok bool) {
td.expectEncoding(i, Float64Enc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadFloat64(b), true
v, ok = readFloat64(b), true
}
return
}
@@ -216,7 +216,7 @@ func (td TupleDesc) GetDecimal(i int, tup Tuple) (v string, ok bool) {
td.expectEncoding(i, DecimalEnc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadString(b), true
v, ok = readString(b), true
}
return
}
@@ -227,7 +227,7 @@ func (td TupleDesc) GetTimestamp(i int, tup Tuple) (v time.Time, ok bool) {
td.expectEncoding(i, TimestampEnc, DateEnc, DatetimeEnc, YearEnc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadTimestamp(b), true
v, ok = readTimestamp(b), true
}
return
}
@@ -238,7 +238,7 @@ func (td TupleDesc) GetSqlTime(i int, tup Tuple) (v string, ok bool) {
td.expectEncoding(i, TimeEnc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadString(b), true
v, ok = readString(b), true
}
return
}
@@ -249,7 +249,7 @@ func (td TupleDesc) GetYear(i int, tup Tuple) (v int16, ok bool) {
td.expectEncoding(i, YearEnc)
b := tup.GetField(i)
if b != nil {
v, ok = ReadInt16(b), true
v, ok = readInt16(b), true
}
return
}
@@ -260,7 +260,7 @@ func (td TupleDesc) GetString(i int, tup Tuple) (v string, ok bool) {
td.expectEncoding(i, StringEnc)
b := tup.GetField(i)
if b != nil {
v = ReadString(b)
v = readString(b)
ok = true
}
return