GobySoft / dccl

Dynamic Compact Control Language
Other
17 stars 13 forks source link

Native protobuf #40

Closed tsaubergine closed 5 years ago

tsaubergine commented 5 years ago

Adds support for Protobuf encoding (e.g. varint, zigzag, etc.) of primitive types (all the ints, double, float, bool, enum) as an extension library called libdccl_native_protobuf.so.

Enable using (for all fields in a message) in .proto

option (dccl.msg).codec_group = "dccl.native_protobuf";

or for a single field (in .proto)

message Foo
{
    optional double field_name = 1 [(dccl.field).codec="dccl.native_protobuf"];
}

To load the library:

dccl::Codec codec;
codec.load_library("/path/to/libdccl_native_protobuf.so");

Note, these only use the Protobuf encoding for the data in the fields. No tag is included. Optional fields use a presence bit to indicate if the field is there or not. Repeated fields use the usual DCCL3 repeated prefix length followed by that number of "required" fields.

Sizes are:

||||||| Dynamic Compact Control Language (DCCL) Codec |||||||
1 messages loaded.
Field sizes are in bits unless otherwise noted.
============== 1: dccl.test.NativeProtobufTest ==============
Actual maximum size of message: 270 bytes / 2160 bits
        dccl.id head...........................8
        user head..............................0
        body................................2149
        padding to full byte...................3
Allowed maximum size of message: 1024 bytes / 8192 bits
--------------------------- Header ---------------------------
dccl.id head...................................8 {dccl.default.id}
---------------------------- Body ----------------------------
dccl.test.NativeProtobufTest............365-2149 {dccl.native_protobuf}
        1. double_default_optional..........1-65 {dccl.native_protobuf}
        2. float_default_optional...........1-33 {dccl.native_protobuf}
        3. int32_default_optional...........1-81 {dccl.native_protobuf}
        4. int64_default_optional...........1-81 {dccl.native_protobuf}
        5. uint32_default_optional..........1-41 {dccl.native_protobuf}
        6. uint64_default_optional..........1-81 {dccl.native_protobuf}
        7. sint32_default_optional..........1-41 {dccl.native_protobuf}
        8. sint64_default_optional..........1-81 {dccl.native_protobuf}
        9. fixed32_default_optional.........1-33 {dccl.native_protobuf}
        10. fixed64_default_optional........1-65 {dccl.native_protobuf}
        11. sfixed32_default_optional.......1-33 {dccl.native_protobuf}
        12. sfixed64_default_optional.......1-65 {dccl.native_protobuf}
        13. bool_default_optional............1-9 {dccl.native_protobuf}
        16. enum_default_optional...........1-81 {dccl.native_protobuf}
        21. double_default_required...........64 {dccl.native_protobuf}
        22. float_default_required............32 {dccl.native_protobuf}
        23. int32_default_required..........8-80 {dccl.native_protobuf}
        24. int64_default_required..........8-80 {dccl.native_protobuf}
        25. uint32_default_required.........8-40 {dccl.native_protobuf}
        26. uint64_default_required.........8-80 {dccl.native_protobuf}
        27. sint32_default_required.........8-40 {dccl.native_protobuf}
        28. sint64_default_required.........8-80 {dccl.native_protobuf}
        29. fixed32_default_required..........32 {dccl.native_protobuf}
        30. fixed64_default_required..........64 {dccl.native_protobuf}
        31. sfixed32_default_required.........32 {dccl.native_protobuf}
        32. sfixed64_default_required.........64 {dccl.native_protobuf}
        33. bool_default_required..............8 {dccl.native_protobuf}
        34. enum_default_required...........1-81 {dccl.native_protobuf}
        101. double_default_repeat[4]......3-259 {dccl.native_protobuf}
        103. int32_default_repeat[4].......3-323 {dccl.native_protobuf}