9393//!
9494
9595pub const io = @import ("./io.zig" );
96- const budopts = @import ("budopts" );
96+ pub const LookupTableOptimize = @import ("./budopts.zig" ).LookupTableOptimize ;
97+
98+ pub const lookupTableMode : LookupTableOptimize = @enumFromInt (@intFromEnum (@import ("budopts" ).lookupTable ));
9799
98100test {
99101 _ = io ;
@@ -680,7 +682,7 @@ pub const HeaderType = union(enum) {
680682
681683 /// Convert a value to `HeaderType`.
682684 pub fn from (value : u8 ) ? HeaderType {
683- switch (budopts . lookupTable ) {
685+ switch (lookupTableMode ) {
684686 .all = > {
685687 return lookupAll (value );
686688 },
@@ -693,8 +695,27 @@ pub const HeaderType = union(enum) {
693695 }
694696 }
695697
696- pub fn nextComponentSize (self : @This ()) usize {
697- // TODO: Needs lookup table
698+ /// Look up next component size for the .small level.
699+ ///
700+ /// This function accepts bin64/str64/ext64, which are invalid in the spec.
701+ inline fn lookupNextComponentSize (self : HeaderType ) usize {
702+ const REGULAR = [_ ]usize { 1 , 2 , 4 , 8 };
703+ const FLOAT = [_ ]usize { 4 , 8 };
704+ const ARRAY = [_ ]usize { 2 , 4 };
705+
706+ return switch (self ) {
707+ .nil , .bool , .fixint , .fixarray , .fixmap = > 0 ,
708+ .bin , .str = > | n | REGULAR [n ],
709+ .fixstr = > | n | n ,
710+ .fixext = > | n | 1 + n ,
711+ .ext = > | n | 1 + REGULAR [n ],
712+ .int , .uint = > | n | REGULAR [n ],
713+ .float = > | n | FLOAT [n ],
714+ .array , .map = > | n | ARRAY [n ],
715+ };
716+ }
717+
718+ inline fn findNextComponentSize (self : HeaderType ) usize {
698719 return switch (self ) {
699720 .nil , .bool , .fixint , .fixarray , .fixmap = > 0 ,
700721 .bin , .str = > | n | switch (n ) {
@@ -728,6 +749,26 @@ pub const HeaderType = union(enum) {
728749 };
729750 }
730751
752+ /// Return the next component size of the value.
753+ ///
754+ /// ```
755+ /// | HeaderType | header data | payload |
756+ /// ```
757+ ///
758+ /// - For fixed-number types, return the payload size.
759+ /// - For fixed array and maps, return 0.
760+ /// - For the other types, return the header data size.
761+ pub fn nextComponentSize (self : HeaderType ) usize {
762+ switch (lookupTableMode ) {
763+ .all , .small = > {
764+ return lookupNextComponentSize (self );
765+ },
766+ .none = > {
767+ return findNextComponentSize (self );
768+ },
769+ }
770+ }
771+
731772 pub fn family (self : HeaderType ) ValueTypeFamily {
732773 return switch (self ) {
733774 .nil = > .nil ,
0 commit comments