Skip to content

Commit cb627c1

Browse files
committed
Serialization extensions docs
1 parent 0a22660 commit cb627c1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/src/extensions.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# (De)Serialization Extensions
2+
3+
### Cbor specific
4+
5+
- `isFieldExpected*(T: type): bool`. Overload to return whether the type is an optional obj field. Used for deserializing.
6+
- `shouldWriteObjectField[T](field: T): bool`. Overload to return whether the obj field should be written based on the field-value. Used for serializing. If `true` the field will be omited when `omitOptionalFields` is `true` for the created flavor.
7+
- `writeObjectField(...)` serializes an obj field name and value. Note: Only internal usages found.
8+
9+
### nim-serialization specific
10+
11+
- `writeValue`/`readValue` the main way to overload the (de)serialization for a value type of a given flavor(s).
12+
13+
- `useDefaultSerializationIn(T: untyped, Flavor: type)` generates `writeValue`/`readValue` for a specific type `T`. It only supports `object | ref object | ptr object` types. Relies on `writeRecordValue`/`readRecordValue`.
14+
- `writeRecordValue(w: var FormatWriter, value: object | tuple)`. Overload to write a specific object/tuple.
15+
- `readRecordValue(r: var FormatReader, value: var (object | tuple))`. Overload to read a specific object/tuple.
16+
17+
- `useCustomSerialization(Format: typed, field: untyped, body: untyped)` generates `readFieldIMPL` and `writeFieldIMPL` overloads for the format (flavor or default), `MyObjType` (or `MyObjType.myField`) and (de)serializer body. The difference with `writeValue`/`readValue` is it can be specific to an object field.
18+
- `writeFieldIMPL`. Overload serialize a flavor, object field and value. Otherwise `writeValue` is used.
19+
- `readFieldIMPL`. Overload to deserialize a flavor, object field and value. Otherwise `readValue` is used.
20+
- Note: this is used in `ssz_serialization`, but the usage can be replaced by overloading writeValue/readValue instead as the "field" provided is a `distinct MyType` and not an `objType.field`.
21+
22+
- `generateAutoSerializationAddon(FLAVOR: typed)`. Generates some functions to enable/disable (de)serialization for a flavor. The serialization library needs to check whether the value type is enabled/disable before (de)serializing it.
23+
- `setAutoSerialize(F: type FLAVOR, T: distinct type, val: bool)`. Enable/disable the flavor (de)serialization for type `T`.
24+
- `typeClassOrMemberAutoSerialize(F: type FLAVOR, TC: distinct type, TM: distinct type): bool`. Check whether a type or its parent type class have automatic serialization flag.
25+
- `typeAutoSerialize(F: type FLAVOR, TM: distinct type): bool`. Check if a type has automatic serialization flag.

0 commit comments

Comments
 (0)