Commit 3608e8cd authored by Ray Bellis's avatar Ray Bellis

more jsdocs for packet.js

parent f18575c5
......@@ -143,13 +143,31 @@ class RadiusPacket {
});
}
/**
* Add an attribute to the packet. Called either with a pre-constructed
* {@link Attribute} as a single parameter, or with a key and value
* to construct and place a new attribute in the packet.
*
* @param {(Attribute|number|string|Dictionary.Entry)} attribute - either
* an existing Attribute object, or a key for creating a new one
* @param value - for creating new Attributes, the associated value
* @function
* @throws if the packet is read-only
*/
add(id, value) {
this.attributes.add(id, value);
return this;
}
get(id, vendor, subid) {
const dict = Dictionary.get(id, vendor, subid);
/**
* Get an attribute's value out of the packet. If multiple attributes
* with the same ID exist, only the first is returned.
*
* @param {(number|string)} id - the attribute ID or name
* @return {Attribute}
*/
get(id) {
const dict = Dictionary.get(id);
for (let attr of this.attributes) {
if (attr.dict === dict) {
return attr;
......@@ -158,8 +176,14 @@ class RadiusPacket {
return undefined;
}
getAll(id, vendor, subid) {
const dict = Dictionary.get(id, vendor, subid);
/**
* Get an array of the packet's attributes that match the given ID.
*
* @param {(number|string)} id - the attribute ID or name
* @return {Array<Attribute>}
*/
getAll(id) {
const dict = Dictionary.get(id);
const results = [];
for (let attr of this.attributes) {
if (attr.dict === dict) {
......@@ -200,6 +224,12 @@ class RadiusPacket {
return r;
}
/**
* Generates a buffer containing the packet in wire format.
* @param {string} secret - the shared secret
* @param {boolean} response - whether the packet is a response to a request, or a new request
* @return {Uint8Array}
*/
toWire(secret, response = true) {
let buffer = Buffer.alloc(4096);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment