@@ -60,7 +60,6 @@ import (
6060// which simply produces a larger and still-valid Container.
6161
6262const (
63- Version = 28
6463 MaxMetaSize = 100 * 1024 * 1024
6564 MaxFrameSize = 2 * 1024 * 1024 * 1024
6665 MaxSuperFrameSize = 256 * MaxFrameSize
@@ -80,7 +79,7 @@ type Header interface {
8079// Structure of ColumnFrame
8180//
8281// S U P C (4 byte string)
83- // Version (2 bytes)
82+ // Version (2 bytes) - 6-bit major and 10-bit minor (see Version)
8483// Frame size (8 bytes) - entire frame including header to end of data section
8584// Root ID (4 bytes)
8685// Fused type size (8 bytes) - 0 if not present
@@ -91,20 +90,20 @@ type Header interface {
9190// Fused type value (encoded as raw type value bytes)
9291// Data section (encoded as raw bytes with size = FrameSize - MetadataSize)
9392type ColumnHeader struct {
94- Version uint16 // off 4
95- FrameSize uint64 // 6
96- Root uint32 // 14
97- MetadataSize uint64 // 18
98- TypedefsSize uint64 // 26
99- FusedTypeSize uint64 // 34
93+ Version Version // off 4
94+ FrameSize uint64 // 6
95+ Root uint32 // 14
96+ MetadataSize uint64 // 18
97+ TypedefsSize uint64 // 26
98+ FusedTypeSize uint64 // 34
10099}
101100
102101const ColumnHeaderSize = 42
103102
104103func newColumnHeader (root ID , metadataSize , typedefsSize , fusedTypeSize , dataSectionSize uint64 ) ColumnHeader {
105104 frameSize := ColumnHeaderSize + metadataSize + typedefsSize + fusedTypeSize + dataSectionSize
106105 return ColumnHeader {
107- Version : Version ,
106+ Version : CurrentVersion ,
108107 FrameSize : frameSize ,
109108 Root : uint32 (root ),
110109 MetadataSize : metadataSize ,
@@ -120,7 +119,7 @@ func (c *ColumnHeader) Size() uint64 {
120119func (c ColumnHeader ) Serialize () []byte {
121120 var bytes [ColumnHeaderSize ]byte
122121 copy (bytes [0 :4 ], []byte (ColumnMagic ))
123- binary . LittleEndian . PutUint16 (bytes [4 :], c . Version )
122+ c . Version . Serialize (bytes [4 :])
124123 binary .LittleEndian .PutUint64 (bytes [6 :], c .FrameSize )
125124 binary .LittleEndian .PutUint32 (bytes [14 :], c .Root )
126125 binary .LittleEndian .PutUint64 (bytes [18 :], c .MetadataSize )
@@ -130,7 +129,7 @@ func (c ColumnHeader) Serialize() []byte {
130129}
131130
132131func (c * ColumnHeader ) Deserialize (bytes [ColumnHeaderSize ]byte ) {
133- c .Version = binary . LittleEndian . Uint16 (bytes [4 :])
132+ c .Version . Deserialize (bytes [4 :])
134133 c .FrameSize = binary .LittleEndian .Uint64 (bytes [6 :])
135134 c .Root = binary .LittleEndian .Uint32 (bytes [14 :])
136135 c .MetadataSize = binary .LittleEndian .Uint64 (bytes [18 :])
@@ -174,15 +173,15 @@ func (c ColumnHeader) check() error {
174173// Structure of RowFrame
175174//
176175// S U P R (4 byte string)
177- // Version (2 bytes)
176+ // Version (2 bytes) - 6-bit major and 10-bit minor (see Version)
178177// Frame size (8 bytes) - entire frame including header to end of data section
179178// Fused type size (8 bytes) - 0 if not present
180179// Typedefs section size (8 bytes)
181180// Fused type value (variable bytes)
182181// Typedefs section (variable bytes)
183182// Values section size = FrameSize - (FusedTypeSize+TypedefsSize)
184183type RowHeader struct {
185- Version uint16
184+ Version Version
186185 FrameSize uint64
187186 FusedTypeSize uint64
188187 TypedefsSize uint64
@@ -194,7 +193,7 @@ const RowHeaderSize = 30
194193func newRowHeader (oob bool , typedefsSize , fusedTypeSize , dataSectionSize uint64 ) RowHeader {
195194 frameSize := RowHeaderSize + + typedefsSize + fusedTypeSize + dataSectionSize
196195 return RowHeader {
197- Version : Version ,
196+ Version : CurrentVersion ,
198197 FrameSize : frameSize ,
199198 TypedefsSize : typedefsSize ,
200199 FusedTypeSize : fusedTypeSize ,
@@ -212,15 +211,15 @@ func (r RowHeader) Serialize(ctrl bool) []byte {
212211 } else {
213212 copy (bytes [0 :4 ], []byte (RowMagic ))
214213 }
215- binary . LittleEndian . PutUint16 (bytes [4 :], r . Version )
214+ r . Version . Serialize (bytes [4 :])
216215 binary .LittleEndian .PutUint64 (bytes [6 :], r .FrameSize )
217216 binary .LittleEndian .PutUint64 (bytes [14 :], r .FusedTypeSize )
218217 binary .LittleEndian .PutUint64 (bytes [22 :], r .TypedefsSize )
219218 return bytes [:]
220219}
221220
222221func (r * RowHeader ) Deserialize (bytes [RowHeaderSize ]byte ) {
223- r .Version = binary . LittleEndian . Uint16 (bytes [4 :])
222+ r .Version . Deserialize (bytes [4 :])
224223 r .FrameSize = binary .LittleEndian .Uint64 (bytes [6 :])
225224 r .FusedTypeSize = binary .LittleEndian .Uint64 (bytes [14 :])
226225 r .TypedefsSize = binary .LittleEndian .Uint64 (bytes [22 :])
@@ -254,18 +253,18 @@ func (r RowHeader) check() error {
254253// Structure of SuperFrame footer
255254//
256255// S U P S (4 byte string)
257- // Version (2 bytes)
256+ // Version (2 bytes) - 6-bit major and 10-bit minor (see Version)
258257// Footer size (8 bytes) - total size of footer including SuperFooterPad
259258// Total size of previous SuperFrame (8 bytes) - excludes this SuperFrame footer
260259// Fused type value (variable bytes)
261260// Stats Section (variable bytes)
262261// Footer size (8 bytes) - same as above for backward traversal
263262type SuperFooter struct {
264- Version uint16 // off 4
265- FooterSize uint64 // off 6
266- FusedTypeSize uint64 // off 14
267- StatsSize uint64 // off 22
268- SuperFrameSize uint64 // off 30
263+ Version Version // off 4
264+ FooterSize uint64 // off 6
265+ FusedTypeSize uint64 // off 14
266+ StatsSize uint64 // off 22
267+ SuperFrameSize uint64 // off 30
269268}
270269
271270const (
@@ -275,7 +274,7 @@ const (
275274
276275func newSuperFooter (superFrameSize , fusedTypeSize , statsSize uint64 ) SuperFooter {
277276 return SuperFooter {
278- Version : Version ,
277+ Version : CurrentVersion ,
279278 FooterSize : SuperFooterSize + SuperFooterPad + fusedTypeSize + statsSize ,
280279 FusedTypeSize : fusedTypeSize ,
281280 StatsSize : statsSize ,
@@ -300,7 +299,7 @@ func (s SuperFooter) StatsSection() (int64, int64) {
300299func (s SuperFooter ) Serialize () []byte {
301300 var bytes [SuperFooterSize ]byte
302301 copy (bytes [0 :4 ], []byte (SuperMagic ))
303- binary . LittleEndian . PutUint16 (bytes [4 :], s . Version )
302+ s . Version . Serialize (bytes [4 :])
304303 binary .LittleEndian .PutUint64 (bytes [6 :], s .FooterSize )
305304 binary .LittleEndian .PutUint64 (bytes [14 :], s .FusedTypeSize )
306305 binary .LittleEndian .PutUint64 (bytes [22 :], s .StatsSize )
@@ -309,7 +308,7 @@ func (s SuperFooter) Serialize() []byte {
309308}
310309
311310func (s * SuperFooter ) Deserialize (bytes [SuperFooterSize ]byte ) {
312- s .Version = binary . LittleEndian . Uint16 (bytes [4 :])
311+ s .Version . Deserialize (bytes [4 :])
313312 s .FooterSize = binary .LittleEndian .Uint64 (bytes [6 :])
314313 s .FusedTypeSize = binary .LittleEndian .Uint64 (bytes [14 :])
315314 s .StatsSize = binary .LittleEndian .Uint64 (bytes [22 :])
@@ -455,13 +454,6 @@ func checkEOF(err error) error {
455454 return err
456455}
457456
458- func checkVersion (version uint16 ) error {
459- if version != Version {
460- return fmt .Errorf ("version mismatch: expected %d, found %d" , Version , version )
461- }
462- return nil
463- }
464-
465457func checkSize (msg string , size , max int ) error {
466458 // We check for underflow of size since they are stored as unsigned.
467459 if size > max || size < 0 {
0 commit comments