Socket
Socket
Sign inDemoInstall

@metaplex-foundation/umi-serializers

Package Overview
Dependencies
Maintainers
6
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metaplex-foundation/umi-serializers - npm Package Compare versions

Comparing version 0.8.9 to 0.9.0

LICENSE

3

dist/types/utils.d.ts

@@ -0,5 +1,6 @@

import type { NumberSerializer } from '@metaplex-foundation/umi-serializers-numbers';
import { ArrayLikeSerializerSize } from './arrayLikeSerializerSize';
export declare function getResolvedSize(size: ArrayLikeSerializerSize, childrenSizes: (number | null)[], bytes: Uint8Array, offset: number): [number | bigint, number];
export declare function getResolvedSize(size: number | NumberSerializer, bytes: Uint8Array, offset: number): [number | bigint, number];
export declare function getSizeDescription(size: ArrayLikeSerializerSize | string): string;
export declare function getSizeFromChildren(size: ArrayLikeSerializerSize, childrenSizes: (number | null)[]): number | null;
export declare function getSizePrefix(size: ArrayLikeSerializerSize, realSize: number): Uint8Array;
{
"name": "@metaplex-foundation/umi-serializers",
"version": "0.8.9",
"version": "0.9.0",
"description": "A comprehensive set of serializers for the Umi framework",

@@ -5,0 +5,0 @@ "license": "MIT",

import {
BaseSerializerOptions,
ExpectedFixedSizeSerializerError,
Serializer,

@@ -41,7 +40,2 @@ mergeBytes,

const size = options.size ?? u32();
if (size === 'remainder' && item.fixedSize === null) {
throw new ExpectedFixedSizeSerializerError(
'Serializers of "remainder" size must have fixed-size items.'
);
}
return {

@@ -63,13 +57,16 @@ description:

deserialize: (bytes: Uint8Array, offset = 0) => {
const values: U[] = [];
if (typeof size === 'object' && bytes.slice(offset).length === 0) {
return [[], offset];
return [values, offset];
}
const [resolvedSize, newOffset] = getResolvedSize(
size,
[item.fixedSize],
bytes,
offset
);
if (size === 'remainder') {
while (offset < bytes.length) {
const [value, newOffset] = item.deserialize(bytes, offset);
values.push(value);
offset = newOffset;
}
return [values, offset];
}
const [resolvedSize, newOffset] = getResolvedSize(size, bytes, offset);
offset = newOffset;
const values: U[] = [];
for (let i = 0; i < resolvedSize; i += 1) {

@@ -76,0 +73,0 @@ const [value, newOffset] = item.deserialize(bytes, offset);

import {
BaseSerializerOptions,
ExpectedFixedSizeSerializerError,
mergeBytes,

@@ -9,2 +8,3 @@ Serializer,

import { ArrayLikeSerializerSize } from './arrayLikeSerializerSize';
import { InvalidNumberOfItemsError } from './errors';
import {

@@ -16,3 +16,2 @@ getResolvedSize,

} from './utils';
import { InvalidNumberOfItemsError } from './errors';

@@ -45,10 +44,2 @@ /**

const size = options.size ?? u32();
if (
size === 'remainder' &&
(key.fixedSize === null || value.fixedSize === null)
) {
throw new ExpectedFixedSizeSerializerError(
'Serializers of "remainder" size must have fixed-size items.'
);
}
return {

@@ -76,8 +67,13 @@ description:

}
const [resolvedSize, newOffset] = getResolvedSize(
size,
[key.fixedSize, value.fixedSize],
bytes,
offset
);
if (size === 'remainder') {
while (offset < bytes.length) {
const [deserializedKey, kOffset] = key.deserialize(bytes, offset);
offset = kOffset;
const [deserializedValue, vOffset] = value.deserialize(bytes, offset);
offset = vOffset;
map.set(deserializedKey, deserializedValue);
}
return [map, offset];
}
const [resolvedSize, newOffset] = getResolvedSize(size, bytes, offset);
offset = newOffset;

@@ -84,0 +80,0 @@ for (let i = 0; i < resolvedSize; i += 1) {

import {
BaseSerializerOptions,
ExpectedFixedSizeSerializerError,
mergeBytes,

@@ -9,2 +8,3 @@ Serializer,

import { ArrayLikeSerializerSize } from './arrayLikeSerializerSize';
import { InvalidNumberOfItemsError } from './errors';
import {

@@ -16,3 +16,2 @@ getResolvedSize,

} from './utils';
import { InvalidNumberOfItemsError } from './errors';

@@ -43,7 +42,2 @@ /**

const size = options.size ?? u32();
if (size === 'remainder' && item.fixedSize === null) {
throw new ExpectedFixedSizeSerializerError(
'Serializers of "remainder" size must have fixed-size items.'
);
}
return {

@@ -67,13 +61,16 @@ description:

}
const [resolvedSize, newOffset] = getResolvedSize(
size,
[item.fixedSize],
bytes,
offset
);
if (size === 'remainder') {
while (offset < bytes.length) {
const [value, newOffset] = item.deserialize(bytes, offset);
set.add(value);
offset = newOffset;
}
return [set, offset];
}
const [resolvedSize, newOffset] = getResolvedSize(size, bytes, offset);
offset = newOffset;
for (let i = 0; i < resolvedSize; i += 1) {
const [value, newOffset] = item.deserialize(bytes, offset);
set.add(value);
offset = newOffset;
set.add(value);
}

@@ -80,0 +77,0 @@ return [set, offset];

@@ -1,12 +0,8 @@

import { ExpectedFixedSizeSerializerError } from '@metaplex-foundation/umi-serializers-core';
import type { NumberSerializer } from '@metaplex-foundation/umi-serializers-numbers';
import { ArrayLikeSerializerSize } from './arrayLikeSerializerSize';
import {
InvalidArrayLikeRemainderSizeError,
UnrecognizedArrayLikeSerializerSizeError,
} from './errors';
import { UnrecognizedArrayLikeSerializerSizeError } from './errors';
import { sumSerializerSizes } from './sumSerializerSizes';
export function getResolvedSize(
size: ArrayLikeSerializerSize,
childrenSizes: (number | null)[],
size: number | NumberSerializer,
bytes: Uint8Array,

@@ -23,16 +19,2 @@ offset: number

if (size === 'remainder') {
const childrenSize = sumSerializerSizes(childrenSizes);
if (childrenSize === null) {
throw new ExpectedFixedSizeSerializerError(
'Serializers of "remainder" size must have fixed-size items.'
);
}
const remainder = bytes.slice(offset).length;
if (remainder % childrenSize !== 0) {
throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
}
return [remainder / childrenSize, offset];
}
throw new UnrecognizedArrayLikeSerializerSizeError(size);

@@ -39,0 +21,0 @@ }

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

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc