idlize
1import {Serializer} from "@arkoala/arkui/Serializer"
2
3export function toInt32(value: number, littleEndian: boolean = true): number[] {
4const b0 = (value >> 0 & 0xFF)
5const b1 = (value >> 8 & 0xFF)
6const b2 = (value >> 16 & 0xFF)
7const b3 = (value >> 24 & 0xFF)
8return (littleEndian) ? [b0, b1, b2, b3] : [b3, b2, b1, b0]
9}
10
11export function toStr(value: string): number[] {
12let chars = [...value].map(it => it.charCodeAt(0))
13return [...toInt32(value.length + 1), ...chars, 0] // zero terminated string
14}
15
16export function toArray(s: Serializer): Array<number> {
17return Array.from(s.asArray().slice(0, s.length()))
18}
19