ark::serialization::Object

Defined in header “ark/serialization/object.hh”.


This is an ‘object’ type, which represents a object that we don’t know the concrete type of, but which we can decode from a schema and a bitstream.

This is useful for decoding serialized data and displaying/working with it, assuming you have the schema but not generated code.

Methods

  • Object(Schema schema)
    Constructor. Initializes from the given schema. This ‘object’ can decode messages that were previously serialized with that schema.

    No registry is present, so this is only capable of decoding messages that do not reference other objects or enums.

  • Object(SchemaRegistry registry, Schema schema)
    Constructor. Initializes from the given schema. This ‘object’ can decode messages that were previously serialized with that schema.

    Any nested types will be resolved from the registry.

  • Object(std::shared_ptr< const SchemaRegistry > registry, std::shared_ptr< const Schema > schema)
    Constructor. Initializes from the given schema. This ‘object’ can decode messages that were previously serialized with that schema.

    Any nested types will be resolved from the registry.

  • Object(SchemaRegistry registry, const std::string & type_name)
    Constructor. Initializes from the given registry. The object’s type will match the type name given, but the type will be resolved from the registry.

    Any nested types will be resolved from the registry.

  • Object(std::shared_ptr< const SchemaRegistry > registry, const std::string & type_name)
    Constructor. Initializes from the given registry. The object’s type will match the type name given, but the type will be resolved from the registry.

    Any nested types will be resolved from the registry.

  • void deserialize(InputStream & input)
    Deserializes into this object, based on our supplied schema. Reads data from the given input stream.

  • void deserialize(const core::ByteBuffer & buffer)
    Deserializes into this object, based on our supplied schema. Reads data from the given input stream.

  • const Schema & schema()
    Returns the schema of this object.

  • const SchemaRegistry & schema_registry()
    Returns the schema registry of this object.

  • JsonBlob json()
    Returns the object as a JSON string. This would be equivalent to calling “to_json” on a concrete type.

  • bool has_field(const std::string & name)
    Returns true if the given field is set and contains the specified type.

  • bool contains(const std::string & name)
    Returns true if the given field is set. For example, if a field is optional and not set, this will return false.

  • void reset()
    Resets all of the values stored in this object (clearing out any fields).

  • Type field(const std::string & name)
    Returns the value of the specified field (assuming it exists).

  • void set_field(const std::string & name, const Type & value)
    Sets the field to the specified value. The type must be type that can be stored within a or you will get an error. No type checking is performed.

  • std::string field_as_string(const std::string & field_name)
    Returns the given field, converted to a string, no matter what it’s type is.

    If the field is ’nested’ (ie, name1.name2.name3), it assumes that name1 and name2 are objects that can be descended into.

  • double field_as_double(const std::string & field_name)
    Returns the given field, converted to a double, no matter what it’s type is. Only works on fundamental fields and enums.

    If the field is ’nested’ (ie, name1.name2.name3), it assumes that name1 and name2 are objects that can be descended into.

  • void set_field_as_string(const std::string & name, const std::string & value)
    Sets the given field (by name) as a string. This string will be converted into an appropriate value.

  • std::optional< FieldDescriptor > find_field(const std::string & name)
    Searches through the list of fields in the schema and returns an iterator to the discovered field.

  • void to_json(JsonDocumentWriter & writer, JsonObjectWriter root_object)
    Writes this object out to the given JSON object writer/document pair.