Skip to content

Commit

Permalink
enhance non-primitive depolorizer methods to handle null wire (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvalabs-gokul authored Feb 19, 2024
1 parent e0e9fe5 commit c9604a0
Show file tree
Hide file tree
Showing 74 changed files with 73 additions and 22,182 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ node_modules/
package-lock.json

# Test coverage directory
coverage/
coverage/

docs/build
50 changes: 31 additions & 19 deletions dist/depolorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,28 @@ class Depolorizer {
// Peek the wire type of the next element
const data = this.read();
if (schema.fields && schema.fields.values && schema.fields.values.kind) {
const arr = [];
// Get the next element as a pack
// depolorizer with the slice elements
const pack = this.newLoadDepolorizer(data);
// Iterate until loadreader is done
while (!pack.isDone()) {
// Depolorize the element into the element type
const element = pack.depolorize(schema.fields.values);
if (element) {
// const ele = pack.unpack(schema.fields.values, element);
arr.push(element);
switch (data.wire) {
case wiretype_1.WireType.WIRE_PACK: {
// Get the next element as a pack
// depolorizer with the slice elements
const pack = this.newLoadDepolorizer(data);
const arr = [];
// Iterate until loadreader is done
while (!pack.isDone()) {
// Depolorize the element into the element type
const element = pack.depolorize(schema.fields.values);
if (element) {
// const ele = pack.unpack(schema.fields.values, element);
arr.push(element);
}
}
return arr;
}
case wiretype_1.WireType.WIRE_NULL:
return [];
default:
throw new Error('Incompatible wire type');
}
return arr;
}
throw new Error('Invalid kind');
}
Expand Down Expand Up @@ -291,11 +299,11 @@ class Depolorizer {
const data = this.read();
if (schema.fields && schema.fields.keys && schema.fields.values &&
schema.fields.keys.kind && schema.fields.values.kind) {
// Get the next element as a pack
// depolorizer with the slice elements
const pack = this.newLoadDepolorizer(data);
switch (data.wire) {
case wiretype_1.WireType.WIRE_PACK: {
// Get the next element as a pack
// depolorizer with the slice elements
const pack = this.newLoadDepolorizer(data);
const map = new Map();
// Iterate until loadreader is done
while (!pack.isDone()) {
Expand All @@ -306,6 +314,8 @@ class Depolorizer {
}
return map;
}
case wiretype_1.WireType.WIRE_NULL:
return new Map();
default:
throw new Error('Incompatible wire type');
}
Expand All @@ -323,13 +333,13 @@ class Depolorizer {
depolorizeStruct(schema) {
// Peek the wire type of the next element
const data = this.read();
// Get the next element as a pack
// depolorizer with the slice elements
const pack = this.newLoadDepolorizer(data);
switch (data.wire) {
case wiretype_1.WireType.WIRE_PACK: {
const obj = {};
// Get the next element as a pack
// depolorizer with the slice elements
const pack = this.newLoadDepolorizer(data);
const entries = Object.entries(schema.fields);
const obj = {};
let index = 0;
// Iterate until loadreader is done
while (!pack.isDone()) {
Expand All @@ -350,6 +360,8 @@ class Depolorizer {
});
return obj;
}
case wiretype_1.WireType.WIRE_NULL:
return {};
default:
throw new Error('Incompatible wire type');
}
Expand Down
Binary file removed docs/build/doctrees/classes-and-methods.doctree
Binary file not shown.
Binary file removed docs/build/doctrees/contributions.doctree
Binary file not shown.
Binary file removed docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file removed docs/build/doctrees/getting-started.doctree
Binary file not shown.
Binary file removed docs/build/doctrees/index.doctree
Binary file not shown.
Binary file removed docs/build/doctrees/license-and-copyright.doctree
Binary file not shown.
Binary file removed docs/build/doctrees/serialization-formats.doctree
Binary file not shown.
Binary file removed docs/build/doctrees/serialization-schemas.doctree
Binary file not shown.
4 changes: 0 additions & 4 deletions docs/build/html/.buildinfo

This file was deleted.

Loading

0 comments on commit c9604a0

Please sign in to comment.