Skip to content

Serializer class

Serializer encodes and decodes Protocol Buffer messages from a descriptor.

export async function serializeGreeting() {
  const serializer = new Serializer({
    nested: {
      Greeting: {
        fields: { message: { type: "string", id: 1 } },
      },
    },
  });
  const encoded = await serializer.serialize(
    { message: "Hello, Koinos" },
    "Greeting"
  );
  return serializer.deserialize(encoded, "Greeting");
}

View complete file · Run example

This local round trip needs no network connection and checks that the decoded message matches the input.