Giter VIP home page Giter VIP logo

Comments (2)

rolandweber avatar rolandweber commented on August 18, 2024

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:

  1. Whether the PDU is complete, or some data is missing yet.
  2. Where the PDU ends, once it is complete. The beginning of the next PDU might have been received already.
  3. Optional: how much more data is expected. Useful to verify or adjust buffer sizes.
  4. 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.

rolandweber avatar rolandweber commented on August 18, 2024

YAGNI

from pityoulish.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.