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

How to skip some bytes when deserlializer? #2490

Closed
cathaysia opened this issue Jul 4, 2023 · 7 comments
Closed

How to skip some bytes when deserlializer? #2490

cathaysia opened this issue Jul 4, 2023 · 7 comments

Comments

@cathaysia
Copy link

I now have a custom deserializer and a custom Visitor struct. During the deserialization process, some fields in the data stream are not supported, but the length of these fields can be calculated so skip these bytes. Does serde provide some mechanism to skip the these bytes?

IgnoredAny doesn't seem to be used to skip bytes. And if IgnoredAny is used, it will still enter the deserialization process. But I just want those bytes to be simply skipped.

@Mingun
Copy link
Contributor

Mingun commented Jul 4, 2023

Hmm... just skip them in your read stream procedure (I believe that by "have a custom deserializer" you mean "implements its own serialization format" and does not wrap another deserializer)

@cathaysia
Copy link
Author

Hmm... just skip them in your read stream procedure (I believe that by "have a custom deserializer" you mean "implements its own serialization format" and does not wrap another deserializer)

The deserializer contains two deserializers. The first deserializer is used to read fields and split the binary into dictionaries. The second serializer is used to convert the binary into a structure

@cathaysia
Copy link
Author

But whether the field is unknown can only be known in the structure. Therefore, other ways may be needed to skip bytes

@Mingun
Copy link
Contributor

Mingun commented Jul 4, 2023

some fields in the data stream are not supported

Not supported by your deserializer? How your deserializer knows that them are not supported? It read some sign from the data stream? Then skip bytes as soon as you read this sign.

The deserialized type will ask deserializer about data that it contain, so deserializer can just not answer "I have some data" if it cannot understand them but skip them instead.

@cathaysia
Copy link
Author

The form of these data is like this: [(k,v), (k,v)]. where the length of k is fixed and the length of v is explained by k. v is deserialized by one deserializer de1 and (k,v) is deserialized by another deserializer de2.
Among them, the structure maps the fields of the structure to strings through serde(rename), that is, k.
I implemented the visit_map method in the deserialize method for the struct. Check if this field is supported by checking the key. If not supported, require the serializer to be able to skip v

@cathaysia
Copy link
Author

I guess I should call let _: Vec:: = map.next_value()? when k is not supported. Thus storing v in a container so that it can be skipped over. But actually something goes wrong.

@cathaysia
Copy link
Author

I probably figured out what was going on. I will close this issue

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

No branches or pull requests

2 participants