Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shortU16 number format to NumberTypeNode #218

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading