aboutsummaryrefslogtreecommitdiffhomepage
path: root/notes/serialization.txt
blob: 1065361f859cbdb4f28eb98e2ff28b8ae0420939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Serialization
-------------

Solutions:
1. Manual (de-)serialization with compiler checks, so no field gets forgotten.
2. Typeinfo that is passed to a serialization library that does some kind of
   reflection-like operations using the typeinfo (Note: This has to take
   lifetimes, aliasing and modifiability of fields and nested structures into
   account)
3. Compiler-generated calls to the (de-)serialization library of choice.


    func .deserialize_from_der(arena, byte[] bytes) -> Thing or DeserializationError {
        Thing ret = .allocate(arena)
        # XXX temporary arena for parsing?
        DerSequence seq = .from_bytes(arena, bytes) or .malformed
        #Iterator<DerItem> iter = seq.iter()
        DerIterator iter = seq.der_iter()
        ret.a = map_to_some_enum(iter.oid())
        ret.b = iter.integer()
        ret.c = iter.octet_string()
        return ret
    }

Tricky parts:
- enums may be encoded in many different ways in different formats (number, string, OID)
- some formats have multiple different integer types (e.g. uint16, int32, ...)
- some formats have multiple different string types (e.g. PrintableString, OctetString, UTF8String, ...)
- some formats have a choice/variant type, and others don't
- some formats have optional fields, and others don't
- formats can have different case rules. Some might use UpperCase fields, which won't work with SLUL.