new Name(components)
Create a new Name from components.
Parameters:
Name | Type | Description |
---|---|---|
components |
string | Name | Array.<(string|Array.<number>|ArrayBuffer|Buffer|Name)> | if a string, parse it as a URI. If a Name, add a deep copy of its components. Otherwise it is an array of components which are appended according to Name.append, so convert each and store it as an array of Buffer. If a component is a string, encode as utf8. |
Classes
Methods
(static) createNameArray()
Parse uri as a URI and return an array of Buffer components.
(static) fromEscapedString(escapedString) → {Blob}
Make a blob value by decoding the escapedString according to NDN URI Scheme.
If escapedString is "", "." or ".." then return null, which means to skip the
component in the name.
This does not check for a type code prefix such as "sha256digest=".
Parameters:
Name | Type | Description |
---|---|---|
escapedString |
string | The escaped string to decode. |
Returns:
The unescaped Blob value. If the escapedString is not a valid
escaped component, then the Blob isNull().
- Type
- Blob
(static) fromEscapedStringAsBuffer()
- Deprecated:
- Use fromEscapedString. This method returns a Buffer which is the former behavior of fromEscapedString, and should only be used while updating your code.
- Source:
(static) getComponentContentDigestValue()
If component is a ContentDigest, return the digest value as a Buffer slice (don't modify!).
If not a ContentDigest, return null.
A ContentDigest component is Name.ContentDigestPrefix + 32 bytes + Name.ContentDigestSuffix.
(static) toEscapedString(value) → {string}
Return value as an escaped string according to NDN URI Scheme.
We can't use encodeURIComponent because that doesn't encode all the
characters we want to.
This does not add a type code prefix such as "sha256digest=".
Parameters:
Name | Type | Description |
---|---|---|
value |
Buffer | Name.Component | The value or Name.Component to escape. |
Returns:
The escaped string.
- Type
- string
add()
addSegment()
append(component, (number), (number)) → {Name}
Convert the component to a Buffer and append a component to this Name.
Parameters:
Name | Type | Description |
---|---|---|
component |
Name.Component | String | Array.<number> | ArrayBuffer | Buffer | Name | If a component is a string, encode 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. If the component param is a Name or another Name.Component, then this is ignored. | |
(number) |
otherTypeCode (optional) If type is ComponentType.OTHER_CODE, then this is the packet's unrecognized content type code, which must be non-negative. If the component param is a Name or another Name.Component, then this is ignored. |
Returns:
This name so that you can chain calls to append.
- Type
- Name
appendImplicitSha256Digest(digest)
Append 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:
This name so that you can chain calls to append.
appendSegment(segment) → {Name}
Append 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
Parameters:
Name | Type | Description |
---|---|---|
segment |
number | The segment number. |
Returns:
This name so that you can chain calls to append.
- Type
- Name
appendSegmentOffset(segmentOffset) → {Name}
Append 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
Parameters:
Name | Type | Description |
---|---|---|
segmentOffset |
number | The segment byte offset. |
Returns:
This name so that you can chain calls to append.
- Type
- Name
appendSequenceNumber(sequenceNumber)
Append 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
Parameters:
Name | Type | Description |
---|---|---|
sequenceNumber |
number | The sequence number. |
Returns:
This name so that you can chain calls to append.
appendTimestamp(timestamp)
Append 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
Parameters:
Name | Type | Description |
---|---|---|
timestamp |
number | The number of microseconds since the UNIX epoch (Thursday, 1 January 1970) not counting leap seconds. |
Returns:
This name so that you can chain calls to append.
appendVersion(version) → {Name}
Append 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.
Parameters:
Name | Type | Description |
---|---|---|
version |
number | The version number. |
Returns:
This name so that you can chain calls to append.
- Type
- Name
clear()
Clear all the components.
compare(iStartComponent, nComponents, other, iOtherStartComponent, nOtherComponents) → {number}
Compare this to the other Name using NDN canonical ordering. If the first
components of each name are not equal, this returns -1 if the first comes
before the second using the NDN canonical ordering for name components, or 1
if it comes after. If they are equal, this compares the second components of
each name, etc. If both names are the same up to the size of the shorter
name, this returns -1 if the first name is shorter than the second or 1 if it
is longer. For example, std::sort gives: /a/b/d /a/b/cc /c /c/a /bb . This
is intuitive because all names with the prefix /a are next to each other.
But it may be also be counter-intuitive because /c comes before /bb according
to NDN canonical ordering since it is shorter.
The first form of compare is simply compare(other). The second form is
compare(iStartComponent, nComponents, other [, iOtherStartComponent] [, nOtherComponents])
which is equivalent to
self.getSubName(iStartComponent, nComponents).compare
(other.getSubName(iOtherStartComponent, nOtherComponents)) .
Parameters:
Name | Type | Description |
---|---|---|
iStartComponent |
number | The index if the first component of this name to get. If iStartComponent is -N then compare components starting from name.size() - N. |
nComponents |
number | The number of components starting at iStartComponent. If greater than the size of this name, compare until the end of the name. |
other |
Name | The other Name to compare with. |
iOtherStartComponent |
number | (optional) The index if the first component of the other name to compare. If iOtherStartComponent is -N then compare components starting from other.size() - N. If omitted, compare starting from index 0. |
nOtherComponents |
number | (optional) The number of components starting at iOtherStartComponent. If omitted or greater than the size of this name, compare until the end of the name. |
Returns:
0 If they compare equal, -1 if self comes before other in
the canonical ordering, or 1 if self comes after other in the canonical
ordering.
- Type
- number
cut()
equals()
Return true if this Name has the same components as name.
equalsName()
get(i) → {Name.Component}
Get a Name Component by index number.
Parameters:
Name | Type | Description |
---|---|---|
i |
Number | The index of the component, starting from 0. However, if i is negative, return the component at size() - (-i). |
Returns:
The name component at the index. You must not
change the returned Name.Component object.
- Type
- Name.Component
getChangeCount() → {number}
Get the change count, which is incremented each time this object is changed.
Returns:
The change count.
- Type
- number
getComponent()
- Deprecated:
- To get just the component value array, use get(i).getValue().buf().
- Source:
getComponentCount()
getContentDigestValue()
Find the last component in name that has a ContentDigest and return the digest value as Buffer,
or null if not found. See Name.getComponentContentDigestValue.
getName()
getPrefix(nComponents) → {Name}
Return a new Name with the first nComponents components of this Name.
Parameters:
Name | Type | Description |
---|---|---|
nComponents |
number | The number of prefix components. If nComponents is -N then return the prefix up to name.size() - N. For example getPrefix(-1) returns the name without the final component. |
Returns:
A new name.
- Type
- Name
getSubName(iStartComponent, (optional)) → {Name}
Get a new name, constructed as a subset of components.
Parameters:
Name | Type | Description |
---|---|---|
iStartComponent |
number | The index if the first component to get. If iStartComponent is -N then return return components starting from name.size() - N. |
(optional) |
number | nComponents The number of components starting at iStartComponent. If omitted or greater than the size of this name, get until the end of the name. |
Returns:
A new name.
- Type
- Name
getSuccessor() → {Name}
Get the successor of this name which is defined as follows.
N represents the set of NDN Names, and X,Y ∈ N.
Operator < is defined by the NDN canonical order on N.
Y is the successor of X, if (a) X < Y, and (b) ∄ Z ∈ N s.t. X < Z < Y.
In plain words, the successor of a name is the same name, but with its last
component advanced to a next possible value.
Examples:
- The successor of / is /%00
- The successor of /%00%01/%01%02 is /%00%01/%01%03
- The successor of /%00%01/%01%FF is /%00%01/%02%00
- The successor of /%00%01/%FF%FF is /%00%01/%00%00%00
Returns:
A new name which is the successor of this.
- Type
- Name
indexOfFileName()
The "file name" in a name is the last component that isn't blank and doesn't start with one of the
special marker octets (for version, etc.). Return the index in this.components of
the file name, or -1 if not found.
isPrefixOf(name) → {Boolean}
Return true if the N components of this name are the same as the first N
components of the given name.
Parameters:
Name | Type | Description |
---|---|---|
name |
Name | The name to check. |
Returns:
true if this matches the given name. This always returns
true if this name is empty.
- Type
- Boolean
match(name) → {Boolean}
Return true if the N components of this name are the same as the first N
components of the given name.
Parameters:
Name | Type | Description |
---|---|---|
name |
Name | The name to check. |
Returns:
true if this matches the given name. This always returns
true if this name is empty.
- Type
- Boolean
set(uri)
Parse the uri according to the NDN URI Scheme and set the name with the
components.
Parameters:
Name | Type | Description |
---|---|---|
uri |
string | The URI string. |
size() → {number}
Return the number of name components.
Returns:
- Type
- number
to_uri()
toUri(includeScheme) → {String}
Return the escaped name string according to NDN URI Scheme.
Parameters:
Name | Type | Description |
---|---|---|
includeScheme |
boolean | (optional) If true, include the "ndn:" scheme in the URI, e.g. "ndn:/example/name". If false, just return the path, e.g. "/example/name". If ommitted, then just return the path which is the default case where toUri() is used for display. |
Returns:
- Type
- String
wireDecode(input, wireFormat)
Decode the input using a particular wire format and update this Name.
Parameters:
Name | Type | Description |
---|---|---|
input |
Blob | Buffer | The buffer with the bytes to decode. |
wireFormat |
WireFormat | (optional) A WireFormat object used to decode this object. If omitted, use WireFormat.getDefaultWireFormat(). |
wireEncode(wireFormat) → {Blob}
Encode this Name for a particular wire format.
Parameters:
Name | Type | Description |
---|---|---|
wireFormat |
WireFormat | (optional) A WireFormat object used to encode this object. If omitted, use WireFormat.getDefaultWireFormat(). |
Returns:
The encoded buffer in a Blob object.
- Type
- Blob