Guide to Implementing Communication Protocols in C
  • Introduction
  • Code Generation vs C++ Library
  • Main Challenges
  • Goal
  • Audience
  • Code Examples
  • Final Outcome
  • Contribution
  • Message
    • Reading and Writing
    • Dispatching and Handling
    • Extending Interface
  • Fields
    • Automating Basic Operations
    • Working With Fields
    • Common Field Types
  • Generic Library
    • Generalising Message Interface
    • Generalising Message Implementation
    • Generalising Fields Implementation
  • Transport
    • PAYLOAD Layer
    • ID Layer
    • SIZE Layer
    • SYNC Layer
    • CHECKSUM Layer
    • Defining Protocol Stack
  • Achievements
  • Appendices
    • Appendix A - tupleForEach
    • Appendix B - tupleAccumulate
    • Appendix C - tupleForEachFromUntil
    • Appendix D - tupleForEachType
    • Appendix E - AlignedUnion
Powered by GitBook
On this page

Was this helpful?

Fields

PreviousExtending InterfaceNextAutomating Basic Operations

Last updated 5 years ago

Was this helpful?

Every message in any communication protocol has zero or more internal fields, which get serialised in some predefined order and transferred as message payload over I/O link.

Usually developers implement some of explicitly reading and writing all message fields in appropriate functions, such as readImpl() and writeImpl() described in chapter. The primary disadvantage of this approach is an increased development effort when contents of some message need to be modified, i.e. some new field is added, or existing one removed, even when the type of an existing field changes. Having multiple places in the code, that need to be updated, leads to an increased chance of forgetting to update one of the places, or introducing some silly error, which will take time to notice and fix.

This chapter describes how to automate basic operations, such as read and write, i.e. to make it a responsibility of the compiler to generate appropriate code. All the developer needs to do is to define the list of all the field types the message contains, and let the compiler do the job.

boilerplate code
Reading and Writing