# Querying canisters with protobuf

**URL:** <https://forum.dfinity.org/t/querying-canisters-with-protobuf/4548>\
**Category:** Developers\
**Created:** [May 30, 2021, 11:01am UTC](https://forum.dfinity.org/t/querying-canisters-with-protobuf/4548 "2021-05-30T11:01:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/wang/32/446_2.png) [@wang](https://forum.dfinity.org/u/wang)\
**Post date:** [May 30, 2021, 11:01am UTC](https://forum.dfinity.org/t/querying-canisters-with-protobuf/4548/1 "2021-05-30T11:01:33Z")

</div>

I’m trying to query the registry canister using protobuf but getting stuck on encoding. I’m using [protobufjs](https://www.npmjs.com/package/protobufjs), `@dfinity/agent`, and the `.proto` files from ic:

```auto
const argType = root.lookupType("ic_registry_transport.pb.v1.RegistryGetValueRequest")
const retType = root.lookupType("ic_registry_transport.pb.v1.RegistryGetValueResponse")
const emptyArg = argType.encode({}).finish(); // <Buffer >

const result = await agent.query("rwlgt-iiaaa-aaaaa-aaaaa-cai", 
  { methodName: "get_value", emptyArg }
)
retType.decode(result.reply.arg) // valid RegistryGetValueResponse {..}

```

With an empty arg, the request is valid and accepted by the canister. However, when I try with real args, I get an error:

```auto
const arg = argType.encode({ key: Buffer.from("test") }).finish(); // <Buffer 12 04 74 65 73 74>
// returns the following:
RegistryGetValueResponse {
  error: RegistryError {
    code: 1,
    reason: 'Registry Canister Error. Msg: PB error: failed to decode Protobuf message: unexpected end group tag'
  }
}

```

According to this [decoder](https://protogen.marcgravell.com/decode), my input `120474657374` is valid.

Any ideas? @PaulLiu or @hansl maybe?

---

<div class="post-metadata">

**Author:** ![wang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/wang/32/446_2.png) [@wang](https://forum.dfinity.org/u/wang)\
**Post date:** [May 31, 2021, 2:19am UTC](https://forum.dfinity.org/t/querying-canisters-with-protobuf/4548/2 "2021-05-31T02:19:17Z")

</div>

Source:

> **[ic-cubes/agent-pb](https://github.com/ic-cubes/agent-pb)**
>
> An extension of @dfinity/agent to support protobufs

---

<div class="post-metadata">

**Author:** ![wang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/wang/32/446_2.png) [@wang](https://forum.dfinity.org/u/wang)\
**Post date:** [June 1, 2021, 5:55am UTC](https://forum.dfinity.org/t/querying-canisters-with-protobuf/4548/3 "2021-06-01T05:55:53Z")

</div>

Well, turns out it was a JS type error. I was cbor-encoding a `UInt8Array` instead of a `Buffer`. Fixed here: [Ensure arg is buffer · ic-rocks/agent-pb@b9f5413 · GitHub](https://github.com/ic-cubes/agent-pb/commit/b9f541339c21705d882a53eb34106d26fea84fef#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R27)

The question above is solved! New question:

## Is there an official protobuf canister service definition?

I am currently handling annotations like this:

```protobuf
service MyCanister {
  rpc read (google.protobuf.Empty) returns (google.protobuf.UInt64Value) {
    option annotation = query;
  };

  rpc write (google.protobuf.UInt64Value) returns (google.protobuf.Empty) {
    option annotation = update;
  };
}

```
