Constructor
new AnyPacker()
Instantiation not allowed and will throw an error.
- Source:
Examples
// Packing `TypedMessage` instance:
const task = new Task(message, TASK_TYPE);
const anyWithTask = AnyPacker.packTyped(task);
// Packing Protobuf messages:
const anyWithTask = AnyPacker.pack(message).as(TASK_TYPE);
const task = AnyPacker.unpack(anyWithTask).as(TASK_TYPE);
// Packing strings:
const anyWithString = AnyPacker.pack('Presents get packed too!').asString();
console.log(AnyPacker.unpack(anyWithString).asString());
// Out: Presents get packed too!
Classes
Methods
(static) pack(valuenon-null) → {Pack}
Creates a new packer for the provided value.
Parameters:
Name | Type | Description |
---|---|---|
value |
* | a value of |
- Source:
Returns:
- Type
- Pack
Examples
// Packing primitive values:
AnyPacker.pack('Presents get packed too!').asString();
// Packing Protobuf messages:
const anyWithTask = AnyPacker.pack(message).as(TASK_TYPE);
(static) packMessage(messagenon-null) → {Any}
Packs a `Message` into a Protobuf `Any`.
Parameters:
Name | Type | Description |
---|---|---|
message |
Message | a message to be packed |
- Source:
Returns:
a new Any with the provided message inside
- Type
- Any
(static) packTyped(messagenon-null) → {Any}
Packs a `TypedMessage` into a Protobuf `Any`.
Parameters:
Name | Type | Description |
---|---|---|
message |
TypedMessage | a message to be packed |
- Source:
Returns:
a new Any with the provided typed message inside
- Type
- Any
(static) unpack(anynon-null) → {Unpack}
Creates a new packer for the provided `Any` instance.
Parameters:
Name | Type | Description |
---|---|---|
any |
Any | a Protobuf `Any` message to unpack |
- Source:
Returns:
an unpacker for the provided `Any` instance
- Type
- Unpack
Examples
// Unpacking messages:
AnyPacker.unpack(anyWithTask).as(TASK_TYPE);
// Unpacking primitive values:
AnyPacker.pack('Presents get packed too!').asString();