UNPKG

@ndn/packet

Version:

NDNts: Network Layer Packets

19 lines (18 loc) 559 B
export const FIELDS = Symbol("@ndn/packet#FIELDS"); export function definePublicFields(typ, fieldDefs) { for (const [field, clearing] of Object.entries(fieldDefs)) { Object.defineProperty(typ.prototype, field, { enumerable: true, get() { return this[FIELDS][field]; }, set(v) { const f = this[FIELDS]; f[field] = v; for (const c of clearing) { f[c] = undefined; } }, }); } }