Select Default Language Display:

  • C++
  • Python
  • JavaScript
  • Java
  • All Languages

Name.Component Class

A Name.Component holds a read-only name component value

[C++]:
#include <ndn-cpp/name.hpp>
Namespace: ndn
[Python]:Module: pyndn
[Java]:Package: net.named_data.jndn

Name.Component Constructors

Name.Component Constructor (copy optional byte array)

Create a new GENERIC Name.Component, optionally copying from the byte array. (To create an ImplicitSha256Digest component, use fromImplicitSha256Digest.)

[C++]:
Name::Component(
    [const std::vector<uint8_t>& value]
);
[Python]:
def __init__(self
    [, value  # bytearray|memoryview|other array of int]
)
[JavaScript]:
Name.Component = function NameComponent(
    [value  // Array<number>|ArrayBuffer|Uint8Array]
)
[Java]:
public Component(
    [byte[] value]
)
Parameters:
  • value

    (optional) The content byte array to copy. If omitted, create a Component with an empty value.

Name.Component Constructor (from Unicode string)

Create a new GENERIC Name.Component, converting the value to UTF8 bytes. This does not escape %XX values. If you need to escape, use Name.fromEscapedString.

[Python]:
 def __init__(self,
    value  # unicode (Python 2) or str (Python 3)
)
[JavaScript]:
Name.Component = function NameComponent(
    value  // string
)
[Java]:
Component(
    String value
)
Parameters:
  • value

    The Unicode string which is encoded as UTF8.

    Note

    [Python only] In Python 2, only a value of type ‘unicode’ is encoded as UTF8. A Python 2 ‘str’ is treated as a “raw string” and converted to an array without encoding.

Name.Component Constructor (from Blob)

Create a new GENERIC Name.Component, taking another pointer to the byte array in the Blob. (To create an ImplicitSha256Digest component, use fromImplicitSha256Digest.)

[C++]:
Name::Component(
    const Blob& value
);
[Python]:
 def __init__(self,
    value  # Blob
)
[JavaScript]:
Name.Component = function NameComponent(
    value  // Blob
)
[Java]:
Component(
    Blob value
)
Parameters:
  • value

    The Blob with the pointer to the byte array.

Name.Component Constructor (from Component)

Create a new Name.Component, taking another pointer to the component’s value.

[C++]:
Name::Component(
    const Name::Component& component
);
[Python]:
def __init__(self,
    component  # Name.Component
)
[JavaScript]:
Name.Component = function NameComponent(
    component  // Name.Component
)
[Java]:
Component(
    Component component
)
Parameters:
  • component

    The Name.Component to copy.

Name.Component.compare Method

Compare this to the other Component using NDN canonical ordering.

See http://named-data.net/doc/0.2/technical/CanonicalOrder.html

[C++]:
int compare(
    const Name::Component& other
) const;
[Python]:
# Returns int
def compare(self,
    other  # Name.Component
)
[JavaScript]:
// Returns number
Name.Component.prototype.compare = function(
    other  // Name.Component
)
[Java]:
public final int other(
    Name.Component other
)
Parameters:
  • other

    The other Component to compare with.

Returns:

0 If they compare equal, -1 if this Name.Component comes before other in the canonical ordering, or 1 if this Name.Component comes after other in the canonical ordering.

Name.Component.equals Method

Check if this is the same component as other.

[C++]:
bool equals(
    const Component& other
) const;
[Python]:
# Returns bool
def equals(self,
    other  # Name.Component
)
[JavaScript]:
// Returns boolean
Name.Component.prototype.equals = function(
    other  // Name.Component
)
[Java]:
public boolean equals(
    Name.Component other
)
Parameters:
  • other

    The other Component to compare with.

Returns:

True if the components are not equal, otherwise false.

Name.Component.fromImplicitSha256Digest Method

Create a component of type ImplicitSha256DigestComponent, so that isImplicitSha256Digest() is true.

[C++]:
static Component fromImplicitSha256Digest(
    const Blob& digest
);

static Component fromImplicitSha256Digest(
    const uint8_t *digest,
    size_t digestLength
);

static Component fromImplicitSha256Digest(
    const std::vector<uint8_t>& digest
);
[Python]:
# Returns Name.Component
@staticmethod
def fromImplicitSha256Digest(
    digest  # Blob or value for Blob constructor
)
[JavaScript]:
// Returns Name.Component
Name.Component.fromImplicitSha256Digest = function(
    digest  // Blob|Buffer
)
[Java]:
public static Component fromImplicitSha256Digest(
    Blob digest
)

public static Component fromImplicitSha256Digest(
    byte[] digest
)
Parameters:
  • digest

    The SHA-256 digest value.

Returns:

The new component.

Throw:

Throw an exception if the digest length is not 32 bytes.

Name.Component.getSuccessor Method

Get the successor of this component, as described in Name.getSuccessor.

[C++]:
Component getSuccessor() const;
[Python]:
# Returns Name.Component
def getSuccessor(self)
[JavaScript]:
// Returns Name.Component
Name.Component.prototype.getSuccessor = function()
[Java]:
public final Component getSuccessor()
Returns:

A new Name.Component which is the successor of this.

Name.Component.getValue Method

Get the value of the component.

[C++]:
const Blob& getValue() const;
[Python]:
# Returns Blob
def getValue(self)
[JavaScript]:
// Returns Blob
Name.Component.prototype.getValue = function()
[Java]:
public final Blob getValue()
Returns:

The component value.

Name.Component.isGeneric Method

Check if this component is a generic component.

[C++]:
bool isGeneric() const;
[Python]:
# Returns bool
def isGeneric(self)
[JavaScript]:
// Returns boolean
Name.Component.prototype.isGeneric = function()
[Java]:
public final boolean isGeneric()
Returns:

True if this is an generic component.

Name.Component.isImplicitSha256Digest Method

Check if this component is an ImplicitSha256Digest component.

[C++]:
bool isImplicitSha256Digest() const;
[Python]:
# Returns bool
def isImplicitSha256Digest(self)
[JavaScript]:
// Returns boolean
Name.Component.prototype.isImplicitSha256Digest = function()
[Java]:
public final boolean isImplicitSha256Digest()
Returns:

True if this is an ImplicitSha256Digest component.

Name.Component.toEscapedString Method

Convert this component value 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=”.

[C++]:
std::string toEscapedString() const;
[Python]:
# Returns str
def toEscapedString(self)
[JavaScript]:
// Returns string
Name.Component.prototype.toEscapedString = function()
[Java]:
public final String toEscapedString()
Returns:

The escaped string.

Name.Component From Naming Convention Value Methods

Name.Component.fromNumber Method

Create a component whose value is the nonNegativeInteger encoding of the number. A nonNegativeInteger is always encoded as 1, 2, 4 or 8 bytes.

[C++]:
static Component fromNumber(
    uint64_t number
);
[Python]:
# Returns Name.Component
@staticmethod
def fromNumber(
    number  # int
)
[JavaScript]:
// Returns Name.Component
Name.Component.fromNumber = function(
    number  // number
)
[Java]:
public static Component fromNumber(
    long number
)
Parameters:
  • number

    The number to be encoded.

Returns:

The new component.

Name.Component.fromNumberWithMarker Method

Create a component whose value is the marker appended with the nonNegativeInteger encoding of the number. This is a static method. A nonNegativeInteger is always encoded as 1, 2, 4 or 8 bytes.

[C++]:
static Component fromNumberWithMarker(
    uint64_t number,
    uint8_t marker
);
[Python]:
# Returns Name.Component
@staticmethod
def fromNumberWithMarker(
    number,  # int
    marker   # int
)
[JavaScript]:
// Returns Name.Component
Name.Component.fromNumberWithMarker = function(
    number,  // number
    marker   // number
)
[Java]:
public static Component fromNumberWithMarker(
    long number,
    int marker
)
Parameters:
  • number

    The number to be encoded.

  • marker

    The marker to use as the first byte of the component.

Returns:

The new component.

Name.Component.fromSegment Method

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

[C++]:
static Component fromSegment(
    uint64_t segment
);
[Python]:
# Returns Name.Component
@staticmethod
def fromSegment(
    segment  # int
)
[JavaScript]:
// Returns Name.Component
Name.Component.fromSegment = function(
    segment  // number
)
[Java]:
public static Component fromSegment(
    long segment
)
Parameters:
  • segment

    The integer segment number.

Returns:

The new component.

Name.Component.fromSegmentOffset Method

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

[C++]:
static Component fromSegmentOffset(
    uint64_t segmentOffset
);
[Python]:
# Returns Name.Component
@staticmethod
def fromSegmentOffset(
    segmentOffset  # int
)
[JavaScript]:
// Returns Name.Component
Name.Component.fromSegmentOffset = function(
    segmentOffset  // number
)
[Java]:
public static Component fromSegmentOffset(
    long segmentOffset
)
Parameters:
  • segmentOffset

    The integer segment byte offset.

Returns:

The new component.

Name.Component.fromSequenceNumber Method

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

[C++]:
static Component fromSequenceNumber(
    uint64_t segmentOffset
);
[Python]:
# Returns Name.Component
@staticmethod
def fromSequenceNumber(
    segmentOffset  # int
)
[JavaScript]:
// Returns Name.Component
Name.Component.fromSequenceNumber = function(
    segmentOffset  // number
)
[Java]:
public static Component fromSequenceNumber(
    long segmentOffset
)
Parameters:
  • segmentOffset

    The integer sequence number.

Returns:

The new component.

Name.Component.fromTimestamp Method

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

[C++]:
static Component fromTimestamp(
    uint64_t timestamp
);
[Python]:
# Returns Name.Component
@staticmethod
def fromTimestamp(
    timestamp  # int
)
[JavaScript]:
// Returns Name.Component
Name.Component.fromTimestamp = function(
    timestamp  // number
)
[Java]:
public static Component fromTimestamp(
    long timestamp
)
Parameters:
  • timestamp

    The number of microseconds since the UNIX epoch (Thursday, 1 January 1970) not counting leap seconds.

Returns:

The new component.

Name.Component.fromVersion Method

Create a component with the encoded version number according to NDN naming conventions for “Versioning” (marker 0xFD). Note that this encodes the exact value of version without converting from a time representation. http://named-data.net/doc/tech-memos/naming-conventions.pdf

[C++]:
static Component fromVersion(
    uint64_t version
);
[Python]:
# Returns Name.Component
@staticmethod
def fromVersion(
    version  # int
)
[JavaScript]:
// Returns Name.Component
Name.Component.fromVersion = function(
    version  // number
)
[Java]:
public static Component fromVersion(
    long version
)
Parameters:
  • version

    The integer version number.

Returns:

The new component.

Name.Component Is Naming Convention Value Methods

Name.Component.isSegment Method

Check if this name 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

[C++]:
bool isSegment() const;
[Python]:
# Returns bool
def isSegment(self)
[JavaScript]:
// Returns boolean
Name.Component.prototype.isSegment = function()
[Java]:
public final boolean isSegment()
Returns:

True if this is a segment number.

Name.Component.isSegmentOffset Method

Check if this name 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

[C++]:
bool isSegmentOffset() const;
[Python]:
# Returns bool
def isSegmentOffset(self)
[JavaScript]:
// Returns boolean
Name.Component.prototype.isSegmentOffset = function()
[Java]:
public final boolean isSegmentOffset()
Returns:

True if this is a segment byte offset.

Name.Component.isSequenceNumber Method

Check if this name component is a sequence number according to NDN naming conventions for “Sequencing” (marker 0xFE). http://named-data.net/doc/tech-memos/naming-conventions.pdf

[C++]:
bool isSequenceNumber() const;
[Python]:
# Returns bool
def isSequenceNumber(self)
[JavaScript]:
// Returns boolean
Name.Component.prototype.isSequenceNumber = function()
[Java]:
public final boolean isSequenceNumber()
Returns:

True if this is a sequence number.

Name.Component.isTimestamp Method

Check if this name component is a timestamp according to NDN naming conventions for “Timestamp” (marker 0xFC). http://named-data.net/doc/tech-memos/naming-conventions.pdf

[C++]:
bool isTimestamp() const;
[Python]:
# Returns bool
def isTimestamp(self)
[JavaScript]:
// Returns boolean
Name.Component.prototype.isTimestamp = function()
[Java]:
public final boolean isTimestamp()
Returns:

True if this is a timestamp.

Name.Component.isVersion Method

Check if this name component is a version number according to NDN naming conventions for “Versioning” (marker 0xFD). http://named-data.net/doc/tech-memos/naming-conventions.pdf

[C++]:
bool isVersion() const;
[Python]:
# Returns bool
def isVersion(self)
[JavaScript]:
// Returns boolean
Name.Component.prototype.isVersion = function()
[Java]:
public final boolean isVersion()
Returns:

True if this is a version number.

Name.Component To Naming Convention Value Methods

Name.Component.toNumber Method

Interpret this name component as a network-ordered number and return an integer.

[C++]:
uint64_t toNumber() const;
[Python]:
# Returns int
def toNumber(self)
[JavaScript]:
// Returns number
Name.Component.prototype.toNumber = function()
[Java]:
public final long toNumber()
Returns:

The integer number.

Name.Component.toNumberWithMarker Method

Interpret this name component as a network-ordered number with a marker and return an integer.

[C++]:
uint64_t toNumberWithMarker(
    uint8_t marker
) const;
[Python]:
# Returns int
def toNumberWithMarker(self,
    marker  # int
)
[JavaScript]:
// Returns number
Name.Component.prototype.toNumberWithMarker = function(
    marker  // number
)
[Java]:
public final long toNumberWithMarker(
    int marker
)
Parameters:
  • marker

    The required first byte of the component.

Returns:

The integer number.

Throw:

Throw an exception if the first byte of the component does not equal the marker.

Name.Component.toSegment Method

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

[C++]:
uint64_t toSegment() const;
[Python]:
# Returns int
def toSegment(self)
[JavaScript]:
// Returns number
Name.Component.prototype.toSegment = function()
[Java]:
public final long toSegment()
Returns:

The integer segment number.

Throw:

Throw an exception if the first byte of the component is not the expected marker.

Name.Component.toSegmentOffset Method

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

[C++]:
uint64_t toSegmentOffset() const;
[Python]:
# Returns int
def toSegmentOffset(self)
[JavaScript]:
// Returns number
Name.Component.prototype.toSegmentOffset = function()
[Java]:
public final long toSegmentOffset()
Returns:

The integer segment byte offset.

Throw:

Throw an exception if the first byte of the component is not the expected marker.

Name.Component.toSequenceNumber Method

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

[C++]:
uint64_t toSequenceNumber() const;
[Python]:
# Returns int
def toSequenceNumber(self)
[JavaScript]:
// Returns number
Name.Component.prototype.toSequenceNumber = function()
[Java]:
public final long toSequenceNumber()
Returns:

The integer sequence number.

Throw:

Throw an exception if the first byte of the component is not the expected marker.

Name.Component.toTimestamp Method

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

[C++]:
uint64_t toTimestamp() const;
[Python]:
# Returns int
def toTimestamp(self)
[JavaScript]:
// Returns number
Name.Component.prototype.toTimestamp = function()
[Java]:
public final long toTimestamp()
Returns:

The number of microseconds since the UNIX epoch (Thursday, 1 January 1970) not counting leap seconds.

Throw:

Throw an exception if the first byte of the component is not the expected marker.

Name.Component.toVersion Method

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. http://named-data.net/doc/tech-memos/naming-conventions.pdf

[C++]:
uint64_t toVersion() const;
[Python]:
# Returns int
def toVersion(self)
[JavaScript]:
// Returns number
Name.Component.prototype.toVersion = function()
[Java]:
public final long toVersion()
Returns:

The integer version number.

Throw:

Throw an exception if the first byte of the component is not the expected marker.