@metaplex-foundation/umi-serializer-data-view
Advanced tools
Comparing version 0.7.3 to 0.7.4
{ | ||
"name": "@metaplex-foundation/umi-serializer-data-view", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "A serializer implementation relying on the native DataView API", | ||
@@ -23,3 +23,3 @@ "license": "MIT", | ||
"peerDependencies": { | ||
"@metaplex-foundation/umi": "^0.7.2" | ||
"@metaplex-foundation/umi": "^0.7.4" | ||
}, | ||
@@ -29,3 +29,3 @@ "devDependencies": { | ||
"ava": "^5.1.0", | ||
"@metaplex-foundation/umi": "^0.7.2" | ||
"@metaplex-foundation/umi": "^0.7.4" | ||
}, | ||
@@ -32,0 +32,0 @@ "publishConfig": { |
@@ -391,2 +391,3 @@ import { | ||
): Serializer<T> => { | ||
const prefix = options.size ?? u8(); | ||
const enumKeys = Object.keys(constructor); | ||
@@ -420,11 +421,13 @@ const enumValues = Object.values(constructor); | ||
return { | ||
description: options.description ?? `enum(${valueDescriptions})`, | ||
fixedSize: 1, | ||
maxSize: 1, | ||
description: | ||
options.description ?? | ||
`enum(${valueDescriptions}; ${prefix.description})`, | ||
fixedSize: prefix.fixedSize, | ||
maxSize: prefix.maxSize, | ||
serialize: (value: T) => { | ||
assertValidVariant(value as string | number); | ||
if (typeof value === 'number') return u8().serialize(value); | ||
if (typeof value === 'number') return prefix.serialize(value); | ||
const valueIndex = enumValues.indexOf(value); | ||
if (valueIndex >= 0) return u8().serialize(valueIndex); | ||
return u8().serialize(enumKeys.indexOf(value as string)); | ||
if (valueIndex >= 0) return prefix.serialize(valueIndex); | ||
return prefix.serialize(enumKeys.indexOf(value as string)); | ||
}, | ||
@@ -435,6 +438,10 @@ deserialize: (bytes: Uint8Array, offset = 0) => { | ||
} | ||
const [value, newOffset] = u8().deserialize(bytes, offset); | ||
const [value, newOffset] = prefix.deserialize(bytes, offset); | ||
const valueAsNumber = Number(value); | ||
offset = newOffset; | ||
assertValidVariant(value); | ||
return [(isNumericEnum ? value : enumValues[value]) as T, offset]; | ||
assertValidVariant(valueAsNumber); | ||
return [ | ||
(isNumericEnum ? valueAsNumber : enumValues[valueAsNumber]) as T, | ||
offset, | ||
]; | ||
}, | ||
@@ -448,3 +455,3 @@ }; | ||
): Serializer<T, U> => { | ||
const prefix = options.prefix ?? u8(); | ||
const prefix = options.size ?? u8(); | ||
const fieldDescriptions = variants | ||
@@ -451,0 +458,0 @@ .map( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
294274
2991