spot-sdk-ts
Version:
TypeScript bindings based on protobufs (proto3) provided by Boston Dynamics
165 lines (147 loc) • 4.44 kB
text/typescript
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
export const protobufPackage = "bosdyn.api";
/**
* Represents a chunk of (possibly serialized) data.
* Chunks will be concatenated together to produce a datagram.
* This is to avoid size limit restrictions in grpc implementations.
*/
export interface DataChunk {
/** The total size in bytes of the datagram that this chunk is a part of. */
totalSize: number;
/** Bytes in this data chunk. Bytes are sent sequentially. */
data: Uint8Array;
}
function createBaseDataChunk(): DataChunk {
return { totalSize: 0, data: new Uint8Array() };
}
export const DataChunk = {
encode(
message: DataChunk,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.totalSize !== 0) {
writer.uint32(8).uint64(message.totalSize);
}
if (message.data.length !== 0) {
writer.uint32(18).bytes(message.data);
}
return writer;
},
decode(input: _m0.Reader | Uint8Array, length?: number): DataChunk {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseDataChunk();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.totalSize = longToNumber(reader.uint64() as Long);
break;
case 2:
message.data = reader.bytes();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): DataChunk {
return {
totalSize: isSet(object.totalSize) ? Number(object.totalSize) : 0,
data: isSet(object.data)
? bytesFromBase64(object.data)
: new Uint8Array(),
};
},
toJSON(message: DataChunk): unknown {
const obj: any = {};
message.totalSize !== undefined &&
(obj.totalSize = Math.round(message.totalSize));
message.data !== undefined &&
(obj.data = base64FromBytes(
message.data !== undefined ? message.data : new Uint8Array()
));
return obj;
},
fromPartial<I extends Exact<DeepPartial<DataChunk>, I>>(
object: I
): DataChunk {
const message = createBaseDataChunk();
message.totalSize = object.totalSize ?? 0;
message.data = object.data ?? new Uint8Array();
return message;
},
};
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: any | undefined;
var globalThis: any = (() => {
if (typeof globalThis !== "undefined") return globalThis;
if (typeof self !== "undefined") return self;
if (typeof window !== "undefined") return window;
if (typeof global !== "undefined") return global;
throw "Unable to locate global object";
})();
function bytesFromBase64(b64: string): Uint8Array {
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: Uint8Array): string {
if (globalThis.Buffer) {
return globalThis.Buffer.from(arr).toString("base64");
} else {
const bin: string[] = [];
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
});
return globalThis.btoa(bin.join(""));
}
}
type Builtin =
| Date
| Function
| Uint8Array
| string
| number
| boolean
| undefined;
export type DeepPartial<T> = T extends Builtin
? T
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;
type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin
? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & {
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
};
function longToNumber(long: Long): number {
if (long.gt(Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
return long.toNumber();
}
if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}