netkitty
Version:
Network tools kit
79 lines (78 loc) • 3.23 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VLAN_802dot1Q = void 0;
const BaseHeader_1 = require("../abstracts/BaseHeader");
const NumberToHex_1 = require("../../helper/NumberToHex");
const BufferToHex_1 = require("../../helper/BufferToHex");
class VLAN_802dot1Q extends BaseHeader_1.BaseHeader {
constructor() {
super(...arguments);
this.SCHEMA = {
type: 'object',
properties: {
priority: {
type: 'integer',
minimum: 0,
maximum: 7,
default: 0,
decode: () => {
this.instance.priority.setValue(this.readBits(0, 2, 0, 3));
},
encode: () => {
const priorityValue = this.instance.priority.getValue(0);
this.instance.priority.setValue(priorityValue);
this.writeBits(0, 2, 0, 3, priorityValue);
}
},
dei: {
type: 'boolean',
decode: () => {
this.instance.dei.setValue(!!this.readBits(0, 2, 3, 1));
},
encode: () => {
const dei = !!this.instance.dei.getValue();
this.instance.dei.setValue(dei);
this.writeBits(0, 2, 3, 1, dei ? 1 : 0);
}
},
id: {
type: 'integer',
minimum: 0,
maximum: 4095,
decode: () => {
this.instance.id.setValue(this.readBits(0, 2, 4, 12));
},
encode: () => {
const vlanId = this.instance.id.getValue(0);
this.instance.id.setValue(vlanId);
this.writeBits(0, 2, 4, 12, vlanId);
}
},
etherType: {
type: 'string',
minLength: 4,
maxLength: 4,
decode: () => {
this.instance.etherType.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(2, 2)));
},
encode: () => {
const etherType = this.instance.etherType.getValue((0, NumberToHex_1.UInt16ToHex)(0x0000), (nodePath) => this.recordError(nodePath, 'Not Found'));
const typeBuffer = Buffer.from(etherType, 'hex');
if (typeBuffer.length < 2)
typeBuffer.fill(0, 0, 1);
this.writeBytes(2, typeBuffer.subarray(0, 2));
}
}
}
};
this.id = 'vlan';
this.name = '802.1Q Virtual LAN';
this.nickname = 'VLAN';
}
match() {
if (!this.prevCodecModule)
return false;
return this.prevCodecModule.instance.etherType.getValue() === (0, NumberToHex_1.UInt16ToHex)(0x8100);
}
}
exports.VLAN_802dot1Q = VLAN_802dot1Q;