Add the raw serialized value to the repeating field in the protocol buffers (protobuf-net, protobuf-csharp)

I am looking for a way to add the serialized value of an object (byte []) to a repeatable field in a protocol buffer message.

I have an application that stores data items in serialized form in memcached and should deliver them to remote clients. The client requests the data items by providing a list of keys, and the server sends back the list of data items. The content of data items is not important to the server; he does not need to know what is contained in them, he only needs to know his key.

The current approach is to retrieve items from memcached, deserialize them, add them to the list of data items in the response, serialize the response to an array of bytes and send it over the socket. This is not optimal, because we deserialize the data elements only so that they are serialized again in the next step. Both serializations (for memcached and for output) are performed using protocol buffers. Ideally, we could skip deserialization after retrieving the data from memcached and add serialized values ​​to the response. I looked into protobuf-net and protobuf-csharp and did not find a way to do this. Is it possible? Did I miss something?

Here are the proto-definitions (simplified):

message Request {    
    required int32 messageId;
    repeated string keys;
}

message DataItem {

    required string key = 1;
    required ValueType type = 2;      // the type of the value, enumeration

    optional int32 intValue = 3;
    optional int64 longValue = 4;
    optional double doubleValue = 5;
    optional float floatValue = 6;
    optional bool boolValue = 7;
    optional string stringValue = 8;
}

message Response {
    required int32 messageId;
    repeated DataItem dataItems;
}
+3
source share
2

, bytes ... , ? , ( protobuf-csharp ) ByteString, (.. blob ).

+1

protobuf:

message RawResponse {
    required int32 messageId;
    repeated bytes dataItems;
}

:

  • memcached RawResponse
  • RawResponse

, RawResponse Response . [1]

0

Source: https://habr.com/ru/post/1758687/


All Articles