GobySoft / dccl

Dynamic Compact Control Language
Other
17 stars 13 forks source link

Feature: Add easy way to create a DCCL codec that doesn't require the use of the ID field within the encoded bytes. #92

Closed tsaubergine closed 10 months ago

tsaubergine commented 1 year ago

I've found a number of cases where I want to encode a DCCL message without the ID field (knowing that this information is available elsewhere).

Make this easier to do.

tsaubergine commented 1 year ago

Likely just use a new message level extension ((dccl.msg).omit_id, defaults to false).

syntax="proto2";
import "dccl/option_extensions.proto";

message NavigationReport {
  option (dccl.msg) = { codec_version: 4
                        omit_id: true
                        max_bytes: 32 };
}

On decode we would somehow pass in the Descriptor to use, such as a new template overload to decode:

template <typename CharIterator, typename ProtobufMessage>
    CharIterator decode(CharIterator begin, CharIterator end, ProtobufMessage* msg,
                        bool header_only = false);

which can be called as:

dccl::Codec codec;
std::string bytes;
NavigationReport report; // we know the type via some external mechanism (or it's the only type we're using on a particular link)
codec.decode(bytes.begin(), bytes.end(), &report);