|
| 1 | +// Auto-generated by lcm-ts. DO NOT EDIT. |
| 2 | + |
| 3 | +import { GoalID } from "./GoalID.ts"; |
| 4 | + |
| 5 | +export class GoalStatus { |
| 6 | + static readonly _HASH = 0xe4d2dccee8caf0e8n; |
| 7 | + static readonly _NAME = "actionlib_msgs.GoalStatus"; |
| 8 | + |
| 9 | + static readonly PENDING = 0; |
| 10 | + static readonly ACTIVE = 1; |
| 11 | + static readonly PREEMPTED = 2; |
| 12 | + static readonly SUCCEEDED = 3; |
| 13 | + static readonly ABORTED = 4; |
| 14 | + static readonly REJECTED = 5; |
| 15 | + static readonly PREEMPTING = 6; |
| 16 | + static readonly RECALLING = 7; |
| 17 | + static readonly RECALLED = 8; |
| 18 | + static readonly LOST = 9; |
| 19 | + |
| 20 | + goal_id: GoalID; |
| 21 | + status: number; |
| 22 | + text: string; |
| 23 | + |
| 24 | + constructor(init?: Partial<GoalStatus>) { |
| 25 | + this.goal_id = init?.goal_id ?? new GoalID(); |
| 26 | + this.status = init?.status ?? 0; |
| 27 | + this.text = init?.text ?? ""; |
| 28 | + } |
| 29 | + |
| 30 | + static decode(data: Uint8Array): GoalStatus { |
| 31 | + const view = new DataView(data.buffer, data.byteOffset, data.byteLength); |
| 32 | + let offset = 0; |
| 33 | + |
| 34 | + // Verify fingerprint |
| 35 | + const hash = view.getBigUint64(offset, false); |
| 36 | + offset += 8; |
| 37 | + if (hash !== GoalStatus._HASH) { |
| 38 | + throw new Error(`Hash mismatch: expected ${GoalStatus._HASH.toString(16)}, got ${hash.toString(16)}`); |
| 39 | + } |
| 40 | + |
| 41 | + const result = new GoalStatus(); |
| 42 | + ({ offset } = GoalStatus._decodeOne(view, offset, result)); |
| 43 | + return result; |
| 44 | + } |
| 45 | + |
| 46 | + static _decodeOne(view: DataView, offset: number, target: GoalStatus): { offset: number } { |
| 47 | + target.goal_id = new GoalID(); |
| 48 | + ({ offset } = GoalID._decodeOne(view, offset, target.goal_id)); |
| 49 | + target.status = view.getUint8(offset); |
| 50 | + offset += 1; |
| 51 | + { |
| 52 | + const len = view.getUint32(offset, false); |
| 53 | + offset += 4; |
| 54 | + target.text = new TextDecoder().decode(new Uint8Array(view.buffer, view.byteOffset + offset, len - 1)); |
| 55 | + offset += len; |
| 56 | + } |
| 57 | + return { offset }; |
| 58 | + } |
| 59 | + |
| 60 | + encode(): Uint8Array { |
| 61 | + const size = 8 + this._encodedSize(); |
| 62 | + const data = new Uint8Array(size); |
| 63 | + const view = new DataView(data.buffer); |
| 64 | + let offset = 0; |
| 65 | + |
| 66 | + // Write fingerprint |
| 67 | + view.setBigUint64(offset, GoalStatus._HASH, false); |
| 68 | + offset += 8; |
| 69 | + |
| 70 | + offset = this._encodeOne(view, offset); |
| 71 | + return data; |
| 72 | + } |
| 73 | + |
| 74 | + _encodeOne(view: DataView, offset: number): number { |
| 75 | + offset = this.goal_id._encodeOne(view, offset); |
| 76 | + view.setUint8(offset, this.status); |
| 77 | + offset += 1; |
| 78 | + { |
| 79 | + const encoded = new TextEncoder().encode(this.text); |
| 80 | + view.setUint32(offset, encoded.length + 1, false); |
| 81 | + offset += 4; |
| 82 | + new Uint8Array(view.buffer, view.byteOffset + offset).set(encoded); |
| 83 | + offset += encoded.length; |
| 84 | + view.setUint8(offset, 0); // null terminator |
| 85 | + offset += 1; |
| 86 | + } |
| 87 | + return offset; |
| 88 | + } |
| 89 | + |
| 90 | + _encodedSize(): number { |
| 91 | + let size = 0; |
| 92 | + size += this.goal_id._encodedSize(); |
| 93 | + size += 1; |
| 94 | + size += 4 + new TextEncoder().encode(this.text).length + 1; |
| 95 | + return size; |
| 96 | + } |
| 97 | +} |
0 commit comments