Hi Ranadheer,

Just a piece of advice, but you may want to try to keep your types as 
strict as possible... i.e. instead of using a general map to store the 
parameters, use an additional type to keep everything easy to represent. 
Something like:

message Tick {
    string subject = 1; // name of the financial instrument - something 
like MSFT, GOOG, etc
    uint64 timestamp = 2; //millis from epoch signifying the timestamp at 
which the object is constructed at the publisher side.
    TickData tick_data = 3;
}

message TickData {
    float ask_price = 1;
    float bid_price = 2;
    float trade_price = 3;
    uint32 trade_size = 4;
}

or even better, just add all the components into one message:

message Tick {
    string subject = 1; // name of the financial instrument - something 
like MSFT, GOOG, etc
    uint64 timestamp = 2; //millis from epoch signifying the timestamp at 
which the object is constructed at the publisher side.
    float ask_price = 3;
    float bid_price = 4;
    float trade_price = 5;
    uint64 trade_size = 6;
...
}

... adding any other possible fields you might have in your data. As well 
as being a lot more compact on-the-wire for bandwidth and CPU improvements, 
this forces you to think about your data and what might be in it, which 
will result in a lot less bugs down the road for you and your client 
consumers. You won't have to worry about typos like accidentally typing 
'bid_prce' or 'bidPrice' or 'bidprice' in the Map. 

Protobuf will not send any fields that are different from their default 
values, so you don't pay any performance penalty for having a lot of 
optional data in the Tick message. You can also still add fields later to 
the message, while keeping backwards compatibility with old consumers.

Also, another little pedantic thing, but if you are using the timestamp 
like Javascript's *Date.now()*, always name it *timestamp_utc *instead of 
just *timestamp*... eventually someone will stuff a local time in there and 
confuse everyone... better to be explicit.

Kevin

On Friday, April 1, 2016 at 7:50:09 PM UTC-5, Feng Xiao wrote:
>
>
>
> On Fri, Apr 1, 2016 at 6:06 AM, Ranadheer Pulluru <[email protected] 
> <javascript:>> wrote:
>
>> Hi,
>>
>> I'm planning to use protobuf for publishing tick data of the financial 
>> instruments. The consumers can be any of the java/python/node.js 
>> languages.The tick is expected to contain various fields like (symbol, 
>> ask_price, bid_price, trade_price, trade_time, trade_size, etc). Basically, 
>> it is sort of a map from field name to the value, where value type can be 
>> any of the primitive types. I thought I can define the schema of the Tick 
>> data structure, using map 
>> <https://developers.google.com/protocol-buffers/docs/proto3#maps>and Any 
>> <https://developers.google.com/protocol-buffers/docs/proto3#any>as 
>> follows
>>
>>
>> syntax = "proto3";
>>
>> package tutorial;
>>
>> import "google/protobuf/any.proto";
>>
>> message Tick {
>>     string subject = 1; // name of the financial instrument - something 
>> like MSFT, GOOG, etc
>>     uint64 timestamp = 2; //millis from epoch signifying the timestamp 
>> at which the object is constructed at the publisher side.
>>     map<string, google.protobuf.Any> fvmap = 3; // the actual map having 
>> field name and values. Something like {ask_price: 10.5, bid_price: 9.5, 
>> trade_price: 10, trade_size=5}
>> }
>>
>> Though I'm able to generate the code in different languages for this 
>> schema, I'm not sure how to populate the values in the *fvmap*.
>>
>> public class TickTest
>> {
>>     public static void main(String[] args)
>>     {
>>         Tick.Builder tick = Tick.newBuilder();
>>         tick.setSubject("ucas");
>>         tick.setTimestamp(System.currentTimeMillis());
>>         Map<String, Any> fvMap = tick.getMutableFvmap();
>> //        fvMap.put("ask", value); // Not sure how to pass values like 
>> 10.5/9.5/10/5 to Any object here.
>>     }
>> }
>>
>>
>>
>> Could you please let me know how to populate the fvMap with different 
>> fields and values here? Please feel tree to tell me if using map  
>> <https://developers.google.com/protocol-buffers/docs/proto3#maps>and Any  
>> <https://developers.google.com/protocol-buffers/docs/proto3#any>is not 
>> the right choice and if there are any better alternatives.
>>
> It seems to me a google.protobuf.Struct suites your purpose better:
>
> https://github.com/google/protobuf/blob/master/src/google/protobuf/struct.proto#L51
>  
>
>>
>> Thanks
>> Ranadheer
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/protobuf.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to