tencent cloud

protobuf.marshal
Last updated: 2025-03-11 20:04:59
protobuf.marshal
Last updated: 2025-03-11 20:04:59
protobuf.marshal is used for pb serialization.
marshal(message: string, value: any): ArrayBuffer

Parameters

Parameter
Type
Description
message
string
The struct name.
value
any
The request body serialized as JSON.

Return

Type
Description
ArrayBuffer
The serialized binary request body.

Samples

Call a method for pb serialization:
import protobuf from 'pts/protobuf';

// Load the demo.proto file from the root directory of the protocol file.
protobuf.load([], 'demo.proto');

// Load the demo.proto file in the dirName directory of the protocol files.
// protobuf.load(['dirName'], 'demo.proto');

export default function () {
// Call marshal for serialization.
const data = protobuf.marshal('xxxx.xxx.demo.stSayHelloReq', { msg: 'pts' });
console.log(data); // [object ArrayBuffer]
// Call unmarshal for deserialization.
const value = protobuf.unmarshal('xxxx.xxx.demo.stSayHelloReq', data);
console.log(JSON.stringify(value)); // {"msg":"pts"}
}

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback