diff --git a/src/compiler.js b/src/compiler.js index 9c8f057..4d5f171 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -62,6 +62,7 @@ class CompiledProtodef { this.sizeOfCtx = sizeOfCtx this.writeCtx = writeCtx this.readCtx = readCtx + this.setVariable('sizeOfCtx', sizeOfCtx) } read (buffer, cursor, type) { @@ -361,6 +362,12 @@ class WriteCompiler extends Compiler { if (args.length > 0) return '(' + code + `)(${value}, buffer, ${offsetExpr}, ` + args.map(name => this.getField(name)).join(', ') + ')' return '(' + code + `)(${value}, buffer, ${offsetExpr})` } + + callTypeSize (value, type, args = []) { + const code = `ctx.sizeOfCtx['${type}']` + if (args.length > 0) return '(' + code + `)(${value}, ` + args.map(name => this.getField(name)).join(', ') + ')' + return '(' + code + `)(${value})` + } } class SizeOfCompiler extends Compiler {