3 ms·
You can apply this same idea to serialization formats. JSON doesn't have a schema. On the other hand, you can think of all JSON values as belonging to this Pr
by haberman 11y ago
You can apply this same idea to serialization formats. JSON doesn't have a schema. On the other hand, you can think of all JSON values as belonging to this Protocol Buffers schema:
message JsonArray {
repeated JsonValue value = 1;
}
message JsonObject {
map<string, JsonValue> properties = 1;
}
message JsonValue {
oneof value {
JsonObject object_value = 1;
JsonArray array_value = 2;
bool is_null = 3;
bool boolean_value = 4;
string string_value = 5;
// Represented as a string because JSON doesn't restrict the
// range/precision of numbers.
string number_value = 6;
}
}
- girvo 11y agoSo, this is something I've been thinking about recently: do you gain much by using Protocol Buffers (et al) for a client-side web application's communication with a server? Having JSON/XMLHttpRequest in the browser by default is such a boon that it'd have to be a lot better as a serialisation format for it to be worth it, but that might actually be the case?