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

fail to encode array of nested classes #27

Closed
FloorLamp opened this issue Mar 7, 2018 · 2 comments
Closed

fail to encode array of nested classes #27

FloorLamp opened this issue Mar 7, 2018 · 2 comments
Assignees
Labels

Comments

@FloorLamp
Copy link

I have 2 classes with custom encoding:

class Serializable {
  serialize () {
    const encoder = new cbor.Encoder()
    this.encodeCBOR(encoder)
    return encoder.finalize()
  }

  static deserialize (serialized) {
    return cbor.decodeAll(serialized)
  }
}

class TestA extends Serializable {
  encodeCBOR (gen) {
    return gen.write(44)
  }
}

class TestB extends Serializable {
  encodeCBOR (gen) {
    return gen.write([
      new TestA()
    ])
  }
}

This works fine and TestB serializes to <Buffer 81 18 2c>. If I update TestB to this:

class TestB extends Serializable {
  encodeCBOR (gen) {
    return gen.write([
      new TestA(),
      true,
    ])
  }
}

Then it serializes to <Buffer 82 18 2c>, which has the correct length but not the new element. Attempting to decode that throws a Error: Undeterminated nesting.

@daviddias
Copy link
Collaborator

@dignifiedquire mind taking a look?

dignifiedquire added a commit that referenced this issue Mar 13, 2018
Due to not returning the success value on `.write`, the encoding was
not finished.

Closes #27
@dignifiedquire
Copy link
Owner

Thanks for the report, fixed in #28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants