-/* Returns strlen(json_to_string(ovsdb_datum_to_json(datum, type), 0)). */
-size_t
-ovsdb_datum_json_length(const struct ovsdb_datum *datum,
- const struct ovsdb_type *type)
-{
- if (ovsdb_type_is_map(type)) {
- size_t length;
-
- /* ["map",[...]]. */
- length = 10;
- if (datum->n > 0) {
- size_t i;
-
- /* Commas between pairs in the inner [...] */
- length += datum->n - 1;
-
- /* [,] in each pair. */
- length += datum->n * 3;
-
- /* Data. */
- for (i = 0; i < datum->n; i++) {
- length += ovsdb_atom_json_length(&datum->keys[i],
- type->key.type);
- length += ovsdb_atom_json_length(&datum->values[i],
- type->value.type);
- }
- }
- return length;
- } else if (datum->n == 1) {
- return ovsdb_atom_json_length(&datum->keys[0], type->key.type);
- } else {
- size_t length;
- size_t i;
-
- /* ["set",[...]]. */
- length = 10;
- if (datum->n > 0) {
- /* Commas between elements in the inner [...]. */
- length += datum->n - 1;
-
- /* Data. */
- for (i = 0; i < datum->n; i++) {
- length += ovsdb_atom_json_length(&datum->keys[i],
- type->key.type);
- }
- }
- return length;
- }
-}
-