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

chore: foundation/src/serialization tech debt #2722

Merged
merged 3 commits into from
Oct 6, 2023
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
8 changes: 4 additions & 4 deletions yarn-project/aztec-sandbox/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ services:
image: otterscan/otterscan:develop
# platform: linux/amd64
ports:
- "5100:80"
- '5100:80'
container_name: otterscan
environment:
# otterscan env var is hardcoded to support erigon client
# but it also works for anvil
- ERIGON_URL=http://127.0.0.1:${SANDBOX_ANVIL_PORT:-8545}
# otterscan env var is hardcoded to support erigon client
# but it also works for anvil
- ERIGON_URL=http://127.0.0.1:${SANDBOX_ANVIL_PORT:-8545}
180 changes: 0 additions & 180 deletions yarn-project/foundation/src/serialize/deserializer.ts

This file was deleted.

26 changes: 5 additions & 21 deletions yarn-project/foundation/src/serialize/free_funcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,11 @@ export function numToUInt8(n: number) {
}

/**
* Serialize a Buffer into a vector format by encoding the length of the buffer and concatenating it with the original buffer.
* The resulting vector consists of a 4-byte header containing the big-endian representation of the original buffer's length, followed by the original buffer.
* This function is useful when storing buffers as data structures with dynamic lengths and later deserializing them using 'deserializeBufferFromVector'.
*
* @param buf - The input Buffer to be serialized into a vector format.
* @returns A Buffer containing the serialized vector with the encoded length header.
* Adds a 4-byte byte-length prefix to a buffer.
* @param buf - The input Buffer to be prefixed
* @returns A Buffer with 4-byte byte-length prefix.
*/
export function serializeBufferToVector(buf: Buffer) {
export function prefixBufferWithLength(buf: Buffer) {
const lengthBuf = Buffer.alloc(4);
lengthBuf.writeUInt32BE(buf.length, 0);
return Buffer.concat([lengthBuf, buf]);
Expand Down Expand Up @@ -131,20 +128,6 @@ export function serializeDate(date: Date) {
return serializeBigInt(BigInt(date.getTime()), 8);
}

/**
* Deserialize a buffer from a vector by reading the length from its first 4 bytes, and then extracting the contents of the buffer.
* The function returns an object containing the deserialized buffer as 'elem' and the number of bytes advanced ('adv') after deserialization.
*
* @param vector - The input buffer containing the serialized vector.
* @param offset - The starting position from where the deserialization should begin (default is 0).
* @returns An object with the deserialized buffer as 'elem' and the number of bytes advanced ('adv') after deserialization.
*/
export function deserializeBufferFromVector(vector: Buffer, offset = 0) {
const length = vector.readUInt32BE(offset);
const adv = 4 + length;
return { elem: vector.subarray(offset + 4, offset + adv), adv };
}

/**
* Deserialize a boolean value from a given buffer at the specified offset.
* Reads a single byte at the provided offset in the buffer and returns
Expand Down Expand Up @@ -225,6 +208,7 @@ export function serializeBufferArrayToVector(arr: Buffer[]) {
* @param vector - The input buffer containing the serialized array.
* @param offset - An optional starting position in the buffer for deserializing the array.
* @returns An object containing the deserialized array and the total number of bytes used during deserialization (adv).
* @deprecated User BufferReader instead.
*/
export function deserializeArrayFromVector<T>(
deserialize: (
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/foundation/src/serialize/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export * from './free_funcs.js';
export * from './deserializer.js';
export * from './serializer.js';
export * from './buffer_reader.js';
export * from './types.js';
89 changes: 0 additions & 89 deletions yarn-project/foundation/src/serialize/serialize.test.ts

This file was deleted.

Loading