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

Give the typedefs to the field encoder #1796

Merged
merged 2 commits into from
Aug 26, 2021
Merged

Give the typedefs to the field encoder #1796

merged 2 commits into from
Aug 26, 2021

Conversation

jameskerr
Copy link
Member

Fixes #1795

The encoding and decoding of a field with a type value was not working correctly. Now we give it all the types in the context when encoding.

@@ -219,7 +219,8 @@ export class ZedContext {
const type = this.lookupTypeRecord([
{name: field.name, type: field.value.type}
])
const transport = type.create([field.value.serialize()], {})

const transport = type.create([field.value.serialize()], {...this.typeById})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mccanne When I encode a single field into zjson (something only done in the app), I create a new record type with that single field, then encode that record. When I use that type to create the record value, I wasn't passing in anything for the typedefs argument. This led to a bug where if a field had a type value, like the string "conn"", it would not find the typedef and get encoded as "null".

I now pass in the typesById object which has all the types in the context. This works, but I want to make sure that it looks right to you too.

Copy link
Contributor

@mason-fish mason-fish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little fuzzy on the zjson type encoding, but the code looks clean to me and the test is very welcome 👍

@jameskerr
Copy link
Member Author

Thanks @mason-fish, I just made the tests even more robust by iterating over each record and each field, then encoding it, decoding it, and checking agains the original.

@jameskerr jameskerr merged commit a988078 into main Aug 26, 2021
@jameskerr jameskerr deleted the copy-type-value branch August 26, 2021 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Right-click "Copy" not adding type definition string to paste buffer
2 participants