What is the point of google.protobuf.StringValue?

There’s a few reasons, mostly to do with where these are used – see struct.proto.

StringValue can be null, string often can’t be in a language interfacing with protobufs. e.g. in Go strings are always set; the “zero value” for a string is “”, the empty string, so it’s impossible to distinguish between “this value is intentionally set to empty string” and “there was no value present”. StringValue can be null and so solves this problem. It’s especially important when they’re used in a StructValue, which may represent arbitrary JSON: to do so it needs to distinguish between a JSON key which was set to empty string (StringValue with an empty string) or a JSON key which wasn’t set at all (null StringValue).

Also if you look at struct.proto, you’ll see that these aren’t fully fledged message types in the proto – they’re all generated from message Value, which has a oneof kind { number_value, string_value, bool_value... etc. By using a oneof struct.proto can represent a variety of different values in one field. Again this makes sense considering what struct.proto is designed to handle – arbitrary JSON – you don’t know what type of value a given JSON key has ahead of time.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)