Skip to content

Commit

Permalink
Add shortU16 number format
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Apr 17, 2024
1 parent 2b36e8b commit 4d7db63
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-suns-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@metaplex-foundation/kinobi": patch
---

Add shortU16 number format
1 change: 1 addition & 0 deletions src/idl/IdlType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const IDL_TYPE_LEAVES = [
'i128',
'f32',
'f64',
'shortU16',
] as const;
export type IdlTypeLeaf = (typeof IDL_TYPE_LEAVES)[number];

Expand Down
5 changes: 3 additions & 2 deletions src/nodes/typeNodes/NumberTypeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export type NumberFormat =
| 'i64'
| 'i128'
| 'f32'
| 'f64';
| 'f64'
| 'shortU16';

export interface NumberTypeNode<TFormat extends NumberFormat = NumberFormat> {
readonly kind: 'numberTypeNode';
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/renderers/rust/getTypeManifestVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4d7db63

Please sign in to comment.