Comments (4)
I have planned changes for the Packet trait, let me know if that's good for your use case.
/// Trait implemented for all toplevel packet declarations.
pub trait Packet: Sized {
type Parent;
/// Try parsing an instance of Packet from the its parent representation.
/// On success, returns the parsed object and the remaining unparsed slice.
/// On failure, returns an error with the reason for the parsing failure.
/// If Packet::Self is a root packet (i.e. Packet::Parent is [u8]) then the
/// behavior of this method is the same as Packet::decode.
fn decode_partial(buf: &Self::Parent) -> Result<Self, DecodeError>;
/// Try parsing an instance of Packet from the input slice.
/// On success, returns the parsed object and the remaining unparsed slice.
/// On failure, returns an error with the reason for the parsing failure.
fn decode_full(buf: &[u8]) -> Result<(Self, &[u8]), DecodeError>;
/// Try parsing an instance of Packet from the input slice.
/// Returns an error if unparsed bytes remain at the end of the input slice.
fn decode(buf: &[u8]) -> Result<Self, DecodeError>;
/// Return the length of the encoded packet.
fn encoded_len(&self) -> usize;
/// Write the packet to an output buffer.
fn encode<T: BufMut>(&self, buf: &mut T) -> Result<(), EncodeError>;
/// Encode the packet to a byte vector.
fn encode_to_vec(&self) -> Result<Vec<u8>, EncodeError>;
/// Encode the packet to a Bytes object.
fn encode_to_bytes(&self) -> Result<Bytes, EncodeError>;
}
from pdl.
Thanks!
Looks like fn encode<T: BufMut>
fits my use case perfectly.
I personally prefer Write
over BufMut
to save myself an import statement, but that's just me being picky!
from pdl.
BufMut is different in that it implies the write cannot fail, where as Write is for fallible I/O operations. So, I think BufMut is the right choice here since it's targeting a buffer rather than a socket, etc.
from pdl.
Ah! I have overlooked the fallibility of Write
.
With that context, I definitely prefer the infallible BufMut
.
from pdl.
Related Issues (20)
- Implement TryInto for Owned values and not only their reference
- Implement snapshot tests and canonical tests for github actions HOT 1
- Create codegen library for use in build.rs
- Add canonical test cases for invalid packet inputs
- Unexpected payload size for non byte aligned payload
- Array element size (20) is not a multiple of 8
- Whitespace is optional between keywords
- CRLF files are not currently supported
- Support Boolean type HOT 1
- Include definitions from other files HOT 1
- Implement support for structure inheritance in the rust generator
- Use relative file path in `pdl` proc macro attribute
- Implement support for optional fields HOT 1
- Feature request: derive `PartialEq` for `enum Error` HOT 1
- Feature request: infallible "from" for custom fields with bits that are a multiple of 8 HOT 2
- Implement support for payload size modifiers in the rust generator
- endianess should include host-order
- Add support for variant constraint values to PDL packet declarations
- Have a way to represent the size of two equal data fields HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdl.