skir_client/serializer

Types

A value that can serialize and deserialize values of type a to/from JSON and binary formats.

Do not construct this directly, use the *_serializer() functions.

pub type Serializer(a) {
  Serializer(internal_adapter: @internal TypeAdapter(a))
}

Constructors

  • Serializer(internal_adapter: @internal TypeAdapter(a))

Values

pub fn from_bytes(
  serializer: Serializer(a),
  bytes: BitArray,
) -> Result(a, String)

Deserializes a value from binary format. Unrecognized fields are dropped.

pub fn from_bytes_with_options(
  serializer: Serializer(a),
  bytes: BitArray,
  keep_unrecognized_values keep_unrecognized_values: Bool,
) -> Result(a, String)

Deserializes a value from binary format. When keep_unrecognized_values is True, field data that this client does not recognise is preserved in unrecognized_fields_.

pub fn from_json_code(
  serializer: Serializer(a),
  json_code: String,
) -> Result(a, String)

Deserializes a value from a JSON string. Accepts both dense and readable JSON. Unrecognized fields are dropped.

pub fn from_json_code_with_options(
  serializer: Serializer(a),
  json_code: String,
  keep_unrecognized_values keep_unrecognized_values: Bool,
) -> Result(a, String)

Deserializes a value from a JSON string. When keep_unrecognized_values is True, field data that this client does not recognise is preserved in unrecognized_fields_ so that re-serializing the value does not silently discard forward-compatible fields.

pub fn json_decoder(
  serializer: Serializer(a),
) -> decode.Decoder(a)

Returns a JSON decoder for this serializer (Drop mode).

pub fn json_decoder_with_options(
  serializer: Serializer(a),
  keep_unrecognized_values keep_unrecognized_values: Bool,
) -> decode.Decoder(a)

Returns a JSON decoder for this serializer with configurable keep/drop mode.

pub fn to_bytes(serializer: Serializer(a), value: a) -> BitArray

Serializes a value to a compact binary format.

pub fn to_dense_json(
  serializer: Serializer(a),
  value: a,
) -> json.Json

Serializes a value to dense (field-index-based) JSON value.

pub fn to_dense_json_code(
  serializer: Serializer(a),
  value: a,
) -> String

Serializes a value to dense (field-index-based) JSON code. Dense JSON is safe for persistent storage: renaming a field does not break deserialization.

pub fn to_readable_json(
  serializer: Serializer(a),
  value: a,
) -> json.Json

Serializes a value to readable (field-name-based) JSON value.

pub fn to_readable_json_code(
  serializer: Serializer(a),
  value: a,
) -> String

Serializes a value to readable (field-name-based, indented) JSON code. Uses 2-space indentation.

pub fn type_descriptor(
  serializer: Serializer(a),
) -> type_descriptor.TypeDescriptor

Returns the TypeDescriptor for the type this serializer handles.

Search Document