JsonValueCodec
Namespace: SnowBank.Data.Json.Binary · class
Implements: IValueEncoder<JsonValue>, IValueEncoder<JsonValue, Slice>
Codec that encodes JsonValue instances into either database keys (ordered) or values (unordered)
Constructors
JsonValueCodec
JsonValueCodec()
JsonValueCodec(CrystalJsonSettings settings, ICrystalJsonTypeResolver resolver = null)
Properties
Resolver
ICrystalJsonTypeResolver Resolver { get; }
Settings
CrystalJsonSettings Settings { get; }
Methods
Append
static IVarTuple Append(IVarTuple prefix, JsonValue value)
Appends a JSON value onto a tuple
prefix— Prefix onto which the key will be added (use Empty if not prefix is needed)value— JSON value to encode. Only primitive types and arrays are supported. Objects are not allowed.
Returns: Tuple that represents this value
Primitive types (like string, number, boolean...) are converted as a single item of a similar type, for ex: "hello" => (...prefix, "hello", )
Arrays are converted as embedded tuples, for ex: [ "hello", "world", 123 ] => (...prefix, ( "hello", "world", 123 ), ).
DecodeJsonArray
static JsonArray DecodeJsonArray(IVarTuple tuple)
DecodeJsonValue
static JsonValue DecodeJsonValue(object o)
DecodeNext
static JsonValue DecodeNext(IVarTuple tuple, out IVarTuple remaining)
Decodes the first element of a tuple, back into a JSON value
tuple— Tuple with a JSON value encoded in the first elementremaining— Receives the rest of the tuple, ornullif this was the last element
Returns: Decoded JSON Value, or Missing if tuple was already empty
This is intended to decode tuples that where previously encoded by or
static JsonValue DecodeNext(IVarTuple tuple, int offset)
Decodes the element at the given location in a tuple, back into a JSON value
tuple— Tuple with a JSON value encoded at some positionoffset— Position, in the tuple, where the encoded value is located.
Returns: Decoded JSON Value, or Missing if offset falls outside of the tuple.
This is intended to decode tuples that where previously encoded by or
DecodeValue
JsonValue DecodeValue(Slice value)
EncodeJsonArray
static IVarTuple EncodeJsonArray(JsonArray value)
EncodeValue
Slice EncodeValue(JsonValue value)
FromTuple
static JsonValue FromTuple(IVarTuple tuple)
ReadKeyFrom
void ReadKeyFrom(ref SliceReader reader, out JsonValue value)
ToTuple
static IVarTuple ToTuple(JsonValue value)
Encodes a JSON value into a tuple
value— JSON value to encode. Only primitive types and arrays are supported. Objects are not allowed.
Returns: Tuple that represents this value
Primitive types (like string, number, boolean...) are converted as a single item of a similar type, for ex: "hello" => ( "hello", )
Arrays are converted as embedded tuples, for ex: [ "hello", "world", 123 ] => ( ( "hello", "world", 123 ), ).
TryReadKeyFrom
bool TryReadKeyFrom(ref SliceReader reader, out JsonValue value)
TryWriteKeyTo
bool TryWriteKeyTo(ref TupleSpanWriter writer, JsonValue value)
WriteKeyTo
void WriteKeyTo(TupleWriter writer, JsonValue value)
void WriteKeyTo(ref SliceWriter writer, JsonValue value)
Fields
Default
static readonly JsonValueCodec Default