new Component(value, (number), (number))
Create a new Name.Component with a copy of the given value.
(To create an ImplicitSha256Digest component, use fromImplicitSha256Digest.)
Parameters:
Name | Type | Description |
---|---|---|
value |
Name.Component | String | Array.<number> | ArrayBuffer | Buffer | If the value is a string, encode it as utf8 (but don't unescape). |
(number) |
type (optional) The component type as an int from the ComponentType enum. If name component type is not a recognized ComponentType enum value, then set this to ComponentType.OTHER_CODE and use the otherTypeCode parameter. If omitted, use ComponentType.GENERIC. | |
(number) |
otherTypeCode (optional) If type is ComponentType.OTHER_CODE, then this is the packet's unrecognized content type code, which must be non-negative. |
Methods
(static) compareBuffers(component1, component2) → {number}
Do the work of Name.Component.compare to compare the component buffers.
Parameters:
Name | Type | Description |
---|---|---|
component1 |
Buffer | |
component2 |
Buffer |
Returns:
0 if they compare equal, -1 if component1 comes before
component2 in the canonical ordering, or 1 if component1 comes after
component2 in the canonical ordering.
- Type
- number
(static) fromImplicitSha256Digest(digest) → {Name.Component}
Create a component of type ImplicitSha256DigestComponent, so that
isImplicitSha256Digest() is true.
Parameters:
Name | Type | Description |
---|---|---|
digest |
Blob | Buffer | The SHA-256 digest value. |
Throws:
DecodingException If the digest length is not 32 bytes.
Returns:
The new Component.
- Type
- Name.Component
(static) fromNumber(number, (number), (number)) → {Name.Component}
Create a component whose value is the nonNegativeInteger encoding of the
number.
Parameters:
Name | Type | Description |
---|---|---|
number |
number | The number to be encoded. |
(number) |
type (optional) The component type as an int from the ComponentType enum. If name component type is not a recognized ComponentType enum value, then set this to ComponentType.OTHER_CODE and use the otherTypeCode parameter. If omitted, use ComponentType.GENERIC. | |
(number) |
otherTypeCode (optional) If type is ComponentType.OTHER_CODE, then this is the packet's unrecognized content type code, which must be non-negative. |
Returns:
The new component value.
- Type
- Name.Component
(static) fromNumberWithMarker(number, marker) → {Name.Component}
Create a component whose value is the marker appended with the
nonNegativeInteger encoding of the number.
Parameters:
Name | Type | Description |
---|---|---|
number |
number | |
marker |
number |
Returns:
- Type
- Name.Component
(static) fromSegment()
Create a component with the encoded segment number according to NDN
naming conventions for "Segment number" (marker 0x00).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
param {number} segment The segment number.
returns {Name.Component} The new Component.
(static) fromSegmentOffset()
Create a component with the encoded segment byte offset according to NDN
naming conventions for segment "Byte offset" (marker 0xFB).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
param {number} segmentOffset The segment byte offset.
returns {Name.Component} The new Component.
(static) fromSequenceNumber()
Create a component with the encoded sequence number according to NDN naming
conventions for "Sequencing" (marker 0xFE).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
param {number} sequenceNumber The sequence number.
returns {Name.Component} The new Component.
(static) fromTimestamp()
Create a component with the encoded timestamp according to NDN naming
conventions for "Timestamp" (marker 0xFC).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
param {number} timestamp The number of microseconds since the UNIX epoch (Thursday,
1 January 1970) not counting leap seconds.
returns {Name.Component} The new Component.
(static) fromVersion()
Create a component with the encoded version number according to NDN
naming conventions for "Versioning" (marker 0xFD).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
Note that this encodes the exact value of version without converting from a
time representation.
param {number} version The version number.
returns {Name.Component} The new Component.
compare(other) → {number}
Compare this to the other Component using NDN canonical ordering.
Parameters:
Name | Type | Description |
---|---|---|
other |
Name.Component | The other Component to compare with. |
Returns:
0 if they compare equal, -1 if this comes before other in
the canonical ordering, or 1 if this comes after other in the canonical
ordering.
- Type
- number
equals(other) → {Boolean}
Check if this is the same component as other.
Parameters:
Name | Type | Description |
---|---|---|
other |
Name.Component | The other Component to compare with. |
Returns:
true if the components are equal, otherwise false.
- Type
- Boolean
getOtherTypeCode()
Get the component type code from the packet which is other than a
recognized ComponentType enum value. This is only meaningful if getType()
is ComponentType.OTHER_CODE.
Returns:
(Number) The type code.
getSuccessor() → {Name.Component}
Get the successor of this component, as described in Name.getSuccessor.
Returns:
A new Name.Component which is the successor of this.
- Type
- Name.Component
getType() → {number}
Get the name component type.
Returns:
The name component type as an int from the ComponentType
enum. If this is ComponentType.OTHER_CODE, then call getOtherTypeCode() to
get the unrecognized component type code.
- Type
- number
getValue() → {Blob}
Get the component value.
Returns:
The component value.
- Type
- Blob
getValueAsBuffer()
- Deprecated:
- Use getValue. This method returns a Buffer which is the former behavior of getValue, and should only be used while updating your code.
- Source:
isGeneric() → {boolean}
Check if this component is a generic component.
Returns:
True if this is an generic component.
- Type
- boolean
isImplicitSha256Digest() → {boolean}
Check if this component is an ImplicitSha256Digest component.
Returns:
True if this is an ImplicitSha256Digest component.
- Type
- boolean
isSegment() → {number}
Check if this component is a segment number according to NDN naming
conventions for "Segment number" (marker 0x00).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
Returns:
True if this is a segment number.
- Type
- number
isSegmentOffset()
Check if this component is a segment byte offset according to NDN
naming conventions for segment "Byte offset" (marker 0xFB).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
Returns:
True if this is a segment byte offset.
isSequenceNumber()
Check if this component is a sequence number according to NDN naming
conventions for "Sequencing" (marker 0xFE).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
Returns:
True if this is a sequence number.
isTimestamp()
Check if this component is a timestamp according to NDN naming
conventions for "Timestamp" (marker 0xFC).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
Returns:
True if this is a timestamp.
isVersion() → {number}
Check if this component is a version number according to NDN naming
conventions for "Versioning" (marker 0xFD).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
Returns:
True if this is a version number.
- Type
- number
toEscapedString() → {string}
Convert this component value to a string by escaping characters according to the NDN URI Scheme.
This also adds "..." to a value with zero or more ".".
This adds a type code prefix as needed, such as "sha256digest=".
Returns:
The escaped string.
- Type
- string
toNumber() → {number}
Interpret this name component as a network-ordered number and return an integer.
Returns:
The integer number.
- Type
- number
toNumberWithMarker(marker) → {number}
Interpret this name component as a network-ordered number with a marker and
return an integer.
Parameters:
Name | Type | Description |
---|---|---|
marker |
number | The required first byte of the component. |
Throws:
Error If the first byte of the component does not equal the marker.
Returns:
The integer number.
- Type
- number
toSegment() → {number}
Interpret this name component as a segment number according to NDN naming
conventions for "Segment number" (marker 0x00).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
Throws:
Error If the first byte of the component is not the expected marker.
Returns:
The integer segment number.
- Type
- number
toSegmentOffset()
Interpret this name component as a segment byte offset according to NDN
naming conventions for segment "Byte offset" (marker 0xFB).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
Throws:
Error If the first byte of the component is not the expected marker.
Returns:
The integer segment byte offset.
toSequenceNumber()
Interpret this name component as a sequence number according to NDN naming
conventions for "Sequencing" (marker 0xFE).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
Throws:
Error If the first byte of the component is not the expected marker.
Returns:
The integer sequence number.
toTimestamp()
Interpret this name component as a timestamp according to NDN naming
conventions for "Timestamp" (marker 0xFC).
http://named-data.net/doc/tech-memos/naming-conventions.pdf
Throws:
Error If the first byte of the component is not the expected marker.
Returns:
The number of microseconds since the UNIX epoch (Thursday,
1 January 1970) not counting leap seconds.
toVersion() → {number}
Interpret this name component as a version number according to NDN naming
conventions for "Versioning" (marker 0xFD). Note that this returns
the exact number from the component without converting it to a time
representation.
Throws:
Error If the first byte of the component is not the expected marker.
Returns:
The integer version number.
- Type
- number