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

Working with more complex types is difficult #14

Open
petreeftime opened this issue Jul 12, 2019 · 1 comment
Open

Working with more complex types is difficult #14

petreeftime opened this issue Jul 12, 2019 · 1 comment

Comments

@petreeftime
Copy link

I'm trying to make some structures serialize into bytes in a nice way. However, these types contain both optional data and maps of bytes (Option<Vec<u8>> and BTreeMap<usize, Vec<u8>>). #[serde(with = "serde_bytes")] doesn't seem capable of dealing with these types. I've found a way to make them work by changing the types to Option<ByteBuf> and BTreeMap<usize, ByteBuf>, but it adds quite a lot of extra glue code. Is there a nicer way to achieve this?

@sfackler
Copy link

sfackler commented Sep 9, 2019

This seems like a question for the serde repository rather than the bytes repository I think?

jonasbb added a commit to jonasbb/serde_with that referenced this issue Mar 11, 2021
The `Bytes` type is heavily inspired by `serde_bytes` and ports it to the
serde_as system.

```rust
value: Vec<u8>,
```

Compared to `serde_bytes` these improvements are available

1. Integration with the `serde_as` annotation.
    /cc serde-rs/bytes#14
2. Implementation for arrays of arbitrary size (Rust 1.51+).
    /cc serde-rs/bytes#26
jonasbb added a commit to jonasbb/serde_with that referenced this issue Mar 11, 2021
The `Bytes` type is heavily inspired by `serde_bytes` and ports it to the
serde_as system.

```rust
#[serde_as(as = "Bytes")]
value: Vec<u8>,
```

Compared to `serde_bytes` these improvements are available

1. Integration with the `serde_as` annotation.
    /cc serde-rs/bytes#14
2. Implementation for arrays of arbitrary size (Rust 1.51+).
    /cc serde-rs/bytes#26
jonasbb added a commit to jonasbb/serde_with that referenced this issue Mar 11, 2021
The `Bytes` type is heavily inspired by `serde_bytes` and ports it to the
serde_as system.

```rust
value: Vec<u8>,
```

Compared to `serde_bytes` these improvements are available

1. Integration with the `serde_as` annotation.
    /cc serde-rs/bytes#14
2. Implementation for arrays of arbitrary size (Rust 1.51+).
    /cc serde-rs/bytes#26
jonasbb added a commit to jonasbb/serde_with that referenced this issue Mar 12, 2021
The `Bytes` type is heavily inspired by `serde_bytes` and ports it to the
serde_as system.

```rust
value: Vec<u8>,
```

Compared to `serde_bytes` these improvements are available

1. Integration with the `serde_as` annotation.
    /cc serde-rs/bytes#14
2. Implementation for arrays of arbitrary size (Rust 1.51+).
    /cc serde-rs/bytes#26
bors bot added a commit to jonasbb/serde_with that referenced this issue Mar 12, 2021
277: Add a `Bytes` type for more efficient byte sequences r=jonasbb a=jonasbb

The `Bytes` type is heavily inspired by `serde_bytes` and ports it to the
serde_as system.

```rust
#[serde_as(as = "Bytes")]
value: Vec<u8>,
```

Compared to `serde_bytes` these improvements are available

1. Integration with the `serde_as` annotation.
    /cc serde-rs/bytes#14
2. Implementation for arrays of arbitrary size (Rust 1.51+).
    /cc serde-rs/bytes#26

Co-authored-by: Jonas Bushart <[email protected]>
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