-
Notifications
You must be signed in to change notification settings - Fork 142
Description
I am trying to use Parser in Angular 5 (using @types/binary-parser).
In order to test the module first I use the IP header example.
when doing that I get the following error
ERROR ReferenceError: Buffer is not defined
at Parser.eval [as compiled] (eval at Parser.compile (webpack-internal:///../../../../binary-parser/lib/binary_parser.js), :3:1)
at Parser.parse (webpack-internal:///../../../../binary-parser/lib/binary_parser.js:337)
at AppComponent.parse (webpack-internal:///../../../../../src/app/app.component.ts:47)
at AppComponent.ngOnInit (webpack-internal:///../../../../../src/app/app.component.ts:21)
at checkAndUpdateDirectiveInline (webpack-internal:///../../../core/esm5/core.js:12596)
at checkAndUpdateNodeInline (webpack-internal:///../../../core/esm5/core.js:14123)
at checkAndUpdateNode (webpack-internal:///../../../core/esm5/core.js:14066)
at debugCheckAndUpdateNode (webpack-internal:///../../../core/esm5/core.js:14959)
at debugCheckDirectivesFn (webpack-internal:///../../../core/esm5/core.js:14900)
at Object.eval [as updateDirectives] (ng:///AppModule/AppComponent_Host.ngfactory.js:8)
If I call Buffer,isBuffer(buf) on my code before calling .parse() it works just fine. I removed this piece of code from binary_parser.js in function getCode and the generated code works fine.
It seems that I am missing something in the declaration of Buffer. It is included in my app.Module. so I can not put the finger on what am I missing?
This is my code as I used it:
`import { Parser } from 'binary-parser';
import { Component } from '@angular/core';
import { OnInit } from '@angular/core/src/metadata/lifecycle_hooks';
import { Buffer } from 'buffer';
@component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
title = 'app';
ngOnInit(): void {
this.parse()
}
parse(){
let ipHeader = new Parser()
.endianess('big')
.bit4('version')
.bit4('headerLength')
.uint8('tos')
.uint16('packetLength')
.uint16('id')
.bit3('offset')
.bit13('fragOffset')
.uint8('ttl')
.uint8('protocol')
.uint16('checksum')
.array('src', {
type: 'uint8',
length: 4
})
.array('dst', {
type: 'uint8',
length: 4
});
const buf = new Buffer('450002c5939900002c06ef98adc24f6c850186d1', 'hex');
Buffer.isBuffer(buf);
// Parse buffer and show result
console.log(ipHeader.parse(buf));
}
}`