alexeyxo/protobuf-swift

Message Field extensions

pffan91 opened this issue · 0 comments

Version of protoc (protoc --version)

libprotoc 3.6.1

Version of ProtocolBuffers.framework

4.0.6

.proto file to reproduce

syntax = "proto3";

import "blerpc.proto";
import "swift-descriptor.proto";

message GetBatteryLevelRequest {
}

// Response message for the ReadBatteryLevel and GetBatteryUpdates methods.
message GetBatteryLevelResponse {
    option (com.blerpc.message) = {
        size_bytes: 1
    };
    // Current device battery level percent.
    int32 battery_level_percent = 1 [(com.blerpc.field) = {
        from_byte: 0
        to_byte: 1
    }];
}

Description

So how can I access to extended properties from_byte and to_byte for each (in this example battery_level_percent) field? Also how can I access to size_bytes of message GetBatteryLevelResponse? I need this to write custom data parser (we already have Android version working with this format). com.blerpc.field described as:

syntax = "proto3";

import "google/protobuf/descriptor.proto";

// A description of a message for automatic converter.
message MessageExtension {
  // Message size in bytes.
  int32 size_bytes = 1;
  // Byte order for the message.
  // Default byte order for the message is BIG_ENDIAN.
  ByteOrder byte_order = 2;
}

// A description of a field for automatic converter.
message FieldExtension {
  // The number of the first byte within a message for a field.
  int32 from_byte = 1;
  // The number of the last byte within a message for a field.
  // This bound is excluded, i.e. {from = 3, to = 5} describes a two-byte field.
  int32 to_byte = 2;
  // Byte order for the field.
  // Default byte order for the field is BIG_ENDIAN.
  ByteOrder byte_order = 3;
}

// Byte order type of message or field converted to bytes.
enum ByteOrder {
  // Default byte order that sets when creating com.blerpc.AnnotationMessageConverter.
  DEFAULT = 0;
  // Big endian byte order. Short number "50" is converted into 2 bytes {0, 50}.
  // This is a default byte order.
  BIG_ENDIAN = 1;
  // Little endian byte order. Short number "50" is converter into 2 bytes {50, 0}".
  LITTLE_ENDIAN = 2;
}

// Allow annotating fields with com.blerpc.field annotation to specify parameters for automatic converter.
extend google.protobuf.FieldOptions {
  FieldExtension field = 82595722;
}

// Allow annotating messages with com.blerpc.message annotation to specify parameters for automatic converter.
extend google.protobuf.MessageOptions {
  MessageExtension message = 82595723;
}

What I need to do:

  1. Receive raw data from BLE device
  2. Parse it in custom format based on information from from_byte, to_byte and size_bytes (I need this info before parsing). I need something like this:

let emptyMessage = GetBatteryLevelResponse() let fromByte = emptyMessage.battery_level_percent.from_byte

So I need to check received data that it is the same as size_bytes described in message, then parse each properties (I think I must have something like GetBatteryLevelResponse.getAllFields) based on from_byte and to to_byte

Any options? Thank you!