Skip to content

Commit b58cf9b

Browse files
committed
Clean up and refactoring
1 parent 06e4794 commit b58cf9b

File tree

3 files changed

+49
-108
lines changed

3 files changed

+49
-108
lines changed

notes.md

-65
This file was deleted.

schemer.go

+2-43
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,6 @@ import (
1717
"strings"
1818
)
1919

20-
// The most signifiant bit indicates whether or not the type is nullable
21-
// The 6 least significant bits identify the type, per below
22-
const (
23-
NullMask = 0x80 // nullable bit
24-
CustomMask = 0x40 // custom schema type bit
25-
26-
FixedIntMask = 0x70 // 0b00 nnns where s is the signed/unsigned bit and n represents the encoded integer size in (8 << n) bits.
27-
FixedIntByte = 0x00
28-
IntSignedMask = 0x01
29-
IntBitsMask = 0x0E
30-
31-
VarIntMask = 0x7E
32-
VarIntByte = 0x10 // 0b01 000s where s is the signed/unsigned bit
33-
34-
FloatMask = 0x7C
35-
FloatBitsMask = 0x01
36-
FloatByte = 0x14 // 0b01 01*n where n is the floating-point size in (32 << n) bits and * is reserved for future use
37-
38-
ComplexMask = 0x7C
39-
ComplexBitsMask = 0x01
40-
ComplexByte = 0x18 // 0b01 10*n where n is the complex number size in (64 << n) bits and * is reserved for future use
41-
42-
BoolMask = 0x7F
43-
BoolByte = 0x1C // 0b01 1100
44-
45-
EnumMask = 0x7F
46-
EnumByte = 0x1D // 0b01 1101
47-
48-
StringMask = 0x7F
49-
VarStringByte = 0x20 // 0b10 000f where f indicates that the string is of fixed byte length
50-
FixedStringByte = 0x21
51-
52-
ArrayMask = 0x7F
53-
VarArrayByte = 0x24 // 0b10 010f where f indicates that the array is of fixed length
54-
FixedArrayByte = 0x25
55-
56-
ObjectMask = 0x7F
57-
VarObjectByte = 0x28 // 0b10 100f where f indicates that the object has fixed number of fields
58-
FixedObjectByte = 0x29
59-
)
60-
6120
// Schema is an interface that encodes and decodes data of a specific type
6221
type Schema interface {
6322
// Encode uses the schema to write the encoded value of i to the output
@@ -729,7 +688,7 @@ func DecodeSchema(r io.Reader) (Schema, error) {
729688
s := &FixedIntSchema{}
730689
s.SetNullable(curByte&NullMask > 0)
731690
s.Signed = curByte&IntSignedMask > 0
732-
s.Bits = 8 << ((curByte & IntBitsMask) >> 1)
691+
s.Bits = 8 << ((curByte & FixedIntBitsMask) >> 1)
733692

734693
return s, nil
735694
}
@@ -861,6 +820,7 @@ func DecodeSchema(r io.Reader) (Schema, error) {
861820
return nil, err
862821
}
863822

823+
varStringSchema := VarStringSchema{}
864824
for i := 0; i < int(numFields); i++ {
865825
of := ObjectField{}
866826

@@ -873,7 +833,6 @@ func DecodeSchema(r io.Reader) (Schema, error) {
873833
// read out each alias name...
874834
for j := 0; j < int(numAliases); j++ {
875835
alias := ""
876-
varStringSchema := VarStringSchema{}
877836

878837
err = varStringSchema.Decode(r, &alias)
879838
if err != nil {

typebyte.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package schemer
2+
3+
// Collection of bit masks and values for the type byte of an encoded schema
4+
const (
5+
NullMask = 0x80 // nullable bit
6+
CustomMask = 0x40 // custom schema bit
7+
CustomIDMask = 0x3F // custom schema identifier
8+
9+
// FixedInt is 0b000 nnns where s is the signed/unsigned bit and
10+
// n represents the encoded integer size in (8 << n) bits.
11+
FixedIntMask = 0x70
12+
FixedIntByte = 0x00
13+
FixedIntBitsMask = 0x0E // Note: Needs to be shifted right 1
14+
IntSignedMask = 0x01
15+
16+
VarIntMask = 0x7E // 0b001 000s where s is the signed/unsigned bit
17+
VarIntByte = 0x10
18+
19+
// Float is 0b001 01nn where n is the floating-point size in (32 << n) bits
20+
FloatMask = 0x7C
21+
FloatBitsMask = 0x03
22+
FloatByte = 0x14
23+
24+
// Complex is 0b001 10nn where n is the complex number size in (64 << n) bits
25+
ComplexMask = 0x7C
26+
ComplexBitsMask = 0x03
27+
ComplexByte = 0x18
28+
29+
BoolMask = 0x7F // 0b001 1100
30+
BoolByte = 0x1C
31+
32+
EnumMask = 0x7F // 0b001 1101
33+
EnumByte = 0x1D
34+
35+
StringMask = 0x7F // 0b010 000f where f indicates fixed-length string
36+
VarStringByte = 0x20
37+
FixedStringByte = 0x21
38+
39+
ArrayMask = 0x7F // 0b010 010f where f indicates fixed-length array
40+
VarArrayByte = 0x24
41+
FixedArrayByte = 0x25
42+
43+
// Object is 0b010 100f where f indicates that the object has fixed fields
44+
ObjectMask = 0x7F
45+
VarObjectByte = 0x28
46+
FixedObjectByte = 0x29
47+
)

0 commit comments

Comments
 (0)