UNPKG

@xmtp/proto

Version:

Protobuf client and generated classes for GRPC API

111 lines (110 loc) 3.62 kB
// Code generated by protoc-gen-ts_proto. DO NOT EDIT. // versions: // protoc-gen-ts_proto v1.181.2 // protoc v3.21.12 // source: message_contents/signed_payload.proto /* eslint-disable */ import Long from "long"; import _m0 from "protobufjs/minimal"; import { Signature } from "./signature.pb"; export const protobufPackage = "xmtp.message_contents"; function createBaseSignedPayload() { return { payload: new Uint8Array(0), signature: undefined }; } export const SignedPayload = { encode(message, writer = _m0.Writer.create()) { if (message.payload.length !== 0) { writer.uint32(10).bytes(message.payload); } if (message.signature !== undefined) { Signature.encode(message.signature, writer.uint32(18).fork()).ldelim(); } return writer; }, decode(input, length) { const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseSignedPayload(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: if (tag !== 10) { break; } message.payload = reader.bytes(); continue; case 2: if (tag !== 18) { break; } message.signature = Signature.decode(reader, reader.uint32()); continue; } if ((tag & 7) === 4 || tag === 0) { break; } reader.skipType(tag & 7); } return message; }, fromJSON(object) { return { payload: isSet(object.payload) ? bytesFromBase64(object.payload) : new Uint8Array(0), signature: isSet(object.signature) ? Signature.fromJSON(object.signature) : undefined, }; }, toJSON(message) { const obj = {}; if (message.payload.length !== 0) { obj.payload = base64FromBytes(message.payload); } if (message.signature !== undefined) { obj.signature = Signature.toJSON(message.signature); } return obj; }, create(base) { return SignedPayload.fromPartial(base ?? {}); }, fromPartial(object) { const message = createBaseSignedPayload(); message.payload = object.payload ?? new Uint8Array(0); message.signature = (object.signature !== undefined && object.signature !== null) ? Signature.fromPartial(object.signature) : undefined; return message; }, }; function bytesFromBase64(b64) { if (globalThis.Buffer) { return Uint8Array.from(globalThis.Buffer.from(b64, "base64")); } else { const bin = globalThis.atob(b64); const arr = new Uint8Array(bin.length); for (let i = 0; i < bin.length; ++i) { arr[i] = bin.charCodeAt(i); } return arr; } } function base64FromBytes(arr) { if (globalThis.Buffer) { return globalThis.Buffer.from(arr).toString("base64"); } else { const bin = []; arr.forEach((byte) => { bin.push(globalThis.String.fromCharCode(byte)); }); return globalThis.btoa(bin.join("")); } } if (_m0.util.Long !== Long) { _m0.util.Long = Long; _m0.configure(); } function isSet(value) { return value !== null && value !== undefined; }