Skip to main content
class Message
import { Message } from "https://deno.land/x/capnp_ts@0.1.0/mod.ts";

Constructors

new
Message(
src?: AnyArena | ArrayBufferView | ArrayBuffer,
packed?,
singleSegment?,
)

A Cap'n Proto message.

SECURITY WARNING: In nodejs do not pass a Buffer's internal array buffer into this constructor. Pass the buffer directly and everything will be fine. If not, your message will potentially be initialized with random memory contents!

The constructor method creates a new Message, optionally using a provided arena for segment allocation, or a buffer to read from.

Properties

readonly
_capnp: _Message

Methods

allocateSegment(byteLength: number): Segment
dump(): string

Create a pretty-printed string dump of this message; incredibly useful for debugging.

WARNING: Do not call this method on large messages!

getRoot<T extends Struct>(RootStruct: StructCtor<T>): T

Get a struct pointer for the root of this message. This is primarily used when reading a message; it will not overwrite existing data.

getSegment(id: number): Segment

Get a segment by its id.

This will lazily allocate the first segment if it doesn't already exist.

initRoot<T extends Struct>(RootStruct: StructCtor<T>): T

Initialize a new message using the provided struct type as the root.

setRoot(src: Pointer): void

Set the root of the message to a copy of the given pointer. Used internally to make copies of pointers for default values.

toArrayBuffer(): ArrayBuffer

Combine the contents of this message's segments into a single array buffer and prepend a stream framing header containing information about the following segment data.

toPackedArrayBuffer(): ArrayBuffer

Like toArrayBuffer(), but also applies the packing algorithm to the output. This is typically what you want to use if you're sending the message over a network link or other slow I/O interface where size matters.

toString(): string

Static Properties

readonly
allocateSegment
readonly
dump
readonly
getRoot
readonly
getSegment
readonly
initRoot
readonly
readRawPointer
readonly
toArrayBuffer
readonly
toPackedArrayBuffer