// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
// versions:
//   protoc-gen-ts_proto  v2.10.1
//   protoc               v3.21.12
// source: SegmentationMask.proto
/* eslint-disable */
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
import { ImgTransformation, Timestamp } from "./common";
export const protobufPackage = "dai.proto.segmentation_mask";
function createBaseSegmentationMask() {
    return {
        ts: undefined,
        tsDevice: undefined,
        sequenceNum: 0,
        transformation: undefined,
        width: 0,
        height: 0,
        data: new Uint8Array(0),
        labels: [],
    };
}
export const SegmentationMask = {
    encode(message, writer = new BinaryWriter()) {
        if (message.ts !== undefined) {
            Timestamp.encode(message.ts, writer.uint32(10).fork()).join();
        }
        if (message.tsDevice !== undefined) {
            Timestamp.encode(message.tsDevice, writer.uint32(18).fork()).join();
        }
        if (message.sequenceNum !== 0) {
            writer.uint32(24).int64(message.sequenceNum);
        }
        if (message.transformation !== undefined) {
            ImgTransformation.encode(message.transformation, writer.uint32(34).fork()).join();
        }
        if (message.width !== 0) {
            writer.uint32(40).int64(message.width);
        }
        if (message.height !== 0) {
            writer.uint32(48).int64(message.height);
        }
        if (message.data.length !== 0) {
            writer.uint32(58).bytes(message.data);
        }
        for (const v of message.labels) {
            writer.uint32(66).string(v);
        }
        return writer;
    },
    decode(input, length) {
        const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
        const end = length === undefined ? reader.len : reader.pos + length;
        const message = createBaseSegmentationMask();
        while (reader.pos < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1: {
                    if (tag !== 10) {
                        break;
                    }
                    message.ts = Timestamp.decode(reader, reader.uint32());
                    continue;
                }
                case 2: {
                    if (tag !== 18) {
                        break;
                    }
                    message.tsDevice = Timestamp.decode(reader, reader.uint32());
                    continue;
                }
                case 3: {
                    if (tag !== 24) {
                        break;
                    }
                    message.sequenceNum = longToNumber(reader.int64());
                    continue;
                }
                case 4: {
                    if (tag !== 34) {
                        break;
                    }
                    message.transformation = ImgTransformation.decode(reader, reader.uint32());
                    continue;
                }
                case 5: {
                    if (tag !== 40) {
                        break;
                    }
                    message.width = longToNumber(reader.int64());
                    continue;
                }
                case 6: {
                    if (tag !== 48) {
                        break;
                    }
                    message.height = longToNumber(reader.int64());
                    continue;
                }
                case 7: {
                    if (tag !== 58) {
                        break;
                    }
                    message.data = reader.bytes();
                    continue;
                }
                case 8: {
                    if (tag !== 66) {
                        break;
                    }
                    message.labels.push(reader.string());
                    continue;
                }
            }
            if ((tag & 7) === 4 || tag === 0) {
                break;
            }
            reader.skip(tag & 7);
        }
        return message;
    },
    fromJSON(object) {
        return {
            ts: isSet(object.ts) ? Timestamp.fromJSON(object.ts) : undefined,
            tsDevice: isSet(object.tsDevice) ? Timestamp.fromJSON(object.tsDevice) : undefined,
            sequenceNum: isSet(object.sequenceNum) ? globalThis.Number(object.sequenceNum) : 0,
            transformation: isSet(object.transformation) ? ImgTransformation.fromJSON(object.transformation) : undefined,
            width: isSet(object.width) ? globalThis.Number(object.width) : 0,
            height: isSet(object.height) ? globalThis.Number(object.height) : 0,
            data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0),
            labels: globalThis.Array.isArray(object?.labels) ? object.labels.map((e) => globalThis.String(e)) : [],
        };
    },
    toJSON(message) {
        const obj = {};
        if (message.ts !== undefined) {
            obj.ts = Timestamp.toJSON(message.ts);
        }
        if (message.tsDevice !== undefined) {
            obj.tsDevice = Timestamp.toJSON(message.tsDevice);
        }
        if (message.sequenceNum !== 0) {
            obj.sequenceNum = Math.round(message.sequenceNum);
        }
        if (message.transformation !== undefined) {
            obj.transformation = ImgTransformation.toJSON(message.transformation);
        }
        if (message.width !== 0) {
            obj.width = Math.round(message.width);
        }
        if (message.height !== 0) {
            obj.height = Math.round(message.height);
        }
        if (message.data.length !== 0) {
            obj.data = base64FromBytes(message.data);
        }
        if (message.labels?.length) {
            obj.labels = message.labels;
        }
        return obj;
    },
    create(base) {
        return SegmentationMask.fromPartial(base ?? {});
    },
    fromPartial(object) {
        const message = createBaseSegmentationMask();
        message.ts = (object.ts !== undefined && object.ts !== null) ? Timestamp.fromPartial(object.ts) : undefined;
        message.tsDevice = (object.tsDevice !== undefined && object.tsDevice !== null)
            ? Timestamp.fromPartial(object.tsDevice)
            : undefined;
        message.sequenceNum = object.sequenceNum ?? 0;
        message.transformation = (object.transformation !== undefined && object.transformation !== null)
            ? ImgTransformation.fromPartial(object.transformation)
            : undefined;
        message.width = object.width ?? 0;
        message.height = object.height ?? 0;
        message.data = object.data ?? new Uint8Array(0);
        message.labels = object.labels?.map((e) => e) || [];
        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(""));
    }
}
function longToNumber(int64) {
    const num = globalThis.Number(int64.toString());
    if (num > globalThis.Number.MAX_SAFE_INTEGER) {
        throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
    }
    if (num < globalThis.Number.MIN_SAFE_INTEGER) {
        throw new globalThis.Error("Value is smaller than Number.MIN_SAFE_INTEGER");
    }
    return num;
}
function isSet(value) {
    return value !== null && value !== undefined;
}
export const protobufName = "SegmentationMask";
//# sourceMappingURL=SegmentationMask.js.map