Comments (2)
General idea: For each incoming PDU, instantiate a stateful helper object. It gets access to the data received so far, and updates when more data comes in. It can tell:
- Whether the PDU is complete, or some data is missing yet.
- Where the PDU ends, once it is complete. The beginning of the next PDU might have been received already.
- Optional: how much more data is expected. Useful to verify or adjust buffer sizes.
- Whether the data is totally screwed up and the connection should be dropped.
There should be a factory interface to instantiate the helper. The factory is stateless and passed to the code that receives data. The helper itself is stateful, so that it can keep track of partially processed PDUs. In the case of TLVs, it can compute the length of the PDU once, as soon as the first four bytes are available.
Tracking data about partially received and processed PDUs isn't that important for TLVs. Computing the length from the two bytes in the header requires no significant effort. For the API design, however, it is important to keep the receiving classes and the interface of the helper independent of the wire format.
Imagine that the wire format is JSON. There is no header with a length. The logic must process JSON data and keep track of how many braces, brackets, double quotes, and escape sequences still need to be closed before the PDU is complete. You wouldn't want to process the JSON data from the start again every time a few more characters have been received. Therefore, the API must allow for stateful helpers.
In the JSON case, it would actually be helpful to fully parse the received data along the way, and then use it without parsing it again. Maybe an API for only detecting the end of a PDU, without parsing it, is not such a good idea after all? Implement a stream parser for PDUs instead?
from pityoulish.
YAGNI
from pityoulish.
Related Issues (20)
- Feedback: Sockets 2019
- Less logging output for Follow-the-Board connections HOT 4
- Sockets: detect response from HTTP server
- Feedback: Java RMI 2019
- Java RMI: prevent multiple tickets for same client HOT 2
- Fix JavaDoc warnings HOT 2
- Java RMI: split off the Direct Messages part
- Build: Travis integration is broken HOT 4
- Take the exercises online HOT 11
- Thread safety for MessageBoard implementations HOT 1
- Run server in IBM Cloud HOT 8
- Push image to public GitHub Container Registry HOT 2
- About deleting container images... HOT 2
- Feedback: Tutorial 2020
- Feedback: Sockets 2020
- Disable Client IP check when running in the Cloud HOT 2
- Upgrade Actions to use environment files HOT 1
- Feedback: Java RMI 2020
- Migrate Travis CI HOT 2
- Transfer repository to the "pityoulish" organization HOT 2
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 pityoulish.