From 69d2698856b65df555c100bc2e2669adcdbce90c Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Wed, 17 Apr 2024 10:05:33 +0100 Subject: [PATCH] Add shortU16 number format (#218) --- .changeset/cold-suns-fail.md | 5 +++++ src/idl/IdlType.ts | 1 + src/nodes/typeNodes/NumberTypeNode.ts | 5 +++-- src/renderers/rust/getTypeManifestVisitor.ts | 6 ++++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changeset/cold-suns-fail.md diff --git a/.changeset/cold-suns-fail.md b/.changeset/cold-suns-fail.md new file mode 100644 index 00000000..291b7611 --- /dev/null +++ b/.changeset/cold-suns-fail.md @@ -0,0 +1,5 @@ +--- +"@metaplex-foundation/kinobi": patch +--- + +Add shortU16 number format diff --git a/src/idl/IdlType.ts b/src/idl/IdlType.ts index 812e919c..bd23eeb5 100644 --- a/src/idl/IdlType.ts +++ b/src/idl/IdlType.ts @@ -77,6 +77,7 @@ export const IDL_TYPE_LEAVES = [ 'i128', 'f32', 'f64', + 'shortU16', ] as const; export type IdlTypeLeaf = (typeof IDL_TYPE_LEAVES)[number]; diff --git a/src/nodes/typeNodes/NumberTypeNode.ts b/src/nodes/typeNodes/NumberTypeNode.ts index 8b8c0811..01021781 100644 --- a/src/nodes/typeNodes/NumberTypeNode.ts +++ b/src/nodes/typeNodes/NumberTypeNode.ts @@ -10,7 +10,8 @@ export type NumberFormat = | 'i64' | 'i128' | 'f32' - | 'f64'; + | 'f64' + | 'shortU16'; export interface NumberTypeNode { readonly kind: 'numberTypeNode'; @@ -32,7 +33,7 @@ export function isSignedInteger(node: NumberTypeNode): boolean { } export function isUnsignedInteger(node: NumberTypeNode): boolean { - return node.format.startsWith('u'); + return node.format.startsWith('u') || node.format === 'shortU16'; } export function isInteger(node: NumberTypeNode): boolean { diff --git a/src/renderers/rust/getTypeManifestVisitor.ts b/src/renderers/rust/getTypeManifestVisitor.ts index 0d78949c..e0fd7b45 100644 --- a/src/renderers/rust/getTypeManifestVisitor.ts +++ b/src/renderers/rust/getTypeManifestVisitor.ts @@ -389,6 +389,12 @@ export function getTypeManifestVisitor() { }, visitNumberType(numberType) { + if (numberType.format === 'shortU16') { + throw new Error( + 'shortU16 numbers are not supported by the Rust renderer' + ); + } + if (numberType.endian === 'le') { return { type: numberType.format,