ProvenPin Install

protobufjs load .proto and encode messages: working versions (tested 2026-10-15)

Load a local .proto fixture with protobufjs, create a message type, and encode/decode binary offline.

passed2 passed · 0 failed2026-10-15 20:57 UTC
Status
passed
Last passed
2026-10-15 20:57 UTC
Tests
2 / 2
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
protobufjs@8.8.1@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38805962781

The code

Exactly the files that passed. Your agent can pull them with get_recipe("protobufjs-proto-encode") (install), or see them on GitHub.

package.json
{
  "name": "protobufjs-proto-encode",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "protobufjs": "8.8.1"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/person.proto
syntax = "proto3";
package demo;

message Person {
  string name = 1;
  int32 id = 2;
  string email = 3;
}
src/codec.ts
import protobuf from "protobufjs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";

const here = dirname(fileURLToPath(import.meta.url));

export type Person = { name: string; id: number; email: string };

export async function loadPersonType() {
  const root = await protobuf.load(join(here, "person.proto"));
  return root.lookupType("demo.Person");
}

export function encodePerson(Type: protobuf.Type, person: Person) {
  const err = Type.verify(person);
  if (err) throw new Error(err);
  const message = Type.create(person);
  return Type.encode(message).finish();
}

export function decodePerson(Type: protobuf.Type, buf: Uint8Array): Person {
  return Type.toObject(Type.decode(buf), { defaults: true }) as Person;
}
test/codec.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { decodePerson, encodePerson, loadPersonType } from "../src/codec.ts";

test("encodes and decodes a Person", async () => {
  const Type = await loadPersonType();
  const person = { name: "Ada", id: 7, email: "[email protected]" };
  const buf = encodePerson(Type, person);
  assert.ok(buf.byteLength > 0);
  assert.deepEqual(decodePerson(Type, buf), person);
});

test("verify rejects missing required shape via bad types", async () => {
  const Type = await loadPersonType();
  // proto3 has no required fields; verify still accepts strings/ints
  const buf = encodePerson(Type, { name: "", id: 0, email: "" });
  assert.deepEqual(decodePerson(Type, buf), { name: "", id: 0, email: "" });
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.