Not sure whether this has been discussed before. In any case...

It would be nice to have mapped fields, e.g. key-value pairs. It would work
similar to repeated fields, which are implicit maps, e.g 0..N keyed
messages. Mapped fields would break from 0..N keys to int or string keys.
Integers are very compact and that is very attractive in terms of wire
format but settle with integer keys are not really greater than 0..N keys.
Thus, string seems more suitable keys of mapped fields. Thus, it seems each
item of a mapped field could be defined by the following template-like proto
message:

message KeyValuePair_of_SomeMessageType {
  required string key = 1;
  optional SomeMessageType value = 2;
}


Let's pick a example. Consider the following messages:

message Foo {
  optional int int_field = 1;
  ...
}

message Bar {
  mapped Foo foo = 1;
}

Internally, protobuf would read the above code as something like:

message Foo {
  optional int int_field = 1;
  ...
}

// Known in code generation time only.
message KeyValuePair_of_Foo {
  required string key = 1;
  optional Foo value = 2;
}

message Bar {
  repeated KeyValuePair_of_Foo foo = 1;
}


And generated C++ code for Bar would look like:

int32 foo_size() const;
bool has_foo(const string& key) const;
const Foo& foo(const string& key) const;
Foo* mutable_foo(const string& key);
void put_foo(const string& key, const Foo& foo);
void remove_foo(const string& key);
const RepeatedPtrField<string>& foo_keys() const;
const RepeatedPtrField<const Foo&>& foo_values() const;


Thoughts?

-Gatis

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to