diff --git a/dagjose/gen/gen.go b/dagjose/gen/gen.go index bff4d34..2f03688 100644 --- a/dagjose/gen/gen.go +++ b/dagjose/gen/gen.go @@ -13,7 +13,8 @@ func main() { ts := schema.TypeSystem{} ts.Init() - // Common types + // -- Common types --> + ts.Accumulate(schema.SpawnString("String")) ts.Accumulate(schema.SpawnBytes("Bytes")) ts.Accumulate(schema.SpawnInt("Int")) @@ -44,28 +45,32 @@ func main() { )) // While `Base64Url` is a `String` type and generated through the schema, it has some (surgical) modifications that - // allow it to be treated as a base64url "lens" looking at raw, un-encoded bytes. + // allow it to be treated as a "base64url string lens" looking at raw, un-encoded bytes. Similarly, while `Raw` is a + // `Bytes` type, it is a "raw bytes lens" with modifications to interpret base64url encoded strings. ts.Accumulate(schema.SpawnString("Base64Url")) + ts.Accumulate(schema.SpawnBytes("Raw")) + + // -- Decode types --> // JWS - ts.Accumulate(schema.SpawnStruct("Signature", []schema.StructField{ + ts.Accumulate(schema.SpawnStruct("DecodedSignature", []schema.StructField{ schema.SpawnStructField("header", "Any", true, false), schema.SpawnStructField("protected", "Base64Url", true, false), schema.SpawnStructField("signature", "Base64Url", false, false), }, schema.SpawnStructRepresentationMap(nil))) - ts.Accumulate(schema.SpawnList("Signatures", "Signature", false)) + ts.Accumulate(schema.SpawnList("DecodedSignatures", "DecodedSignature", false)) // JWE - ts.Accumulate(schema.SpawnStruct("Recipient", []schema.StructField{ + ts.Accumulate(schema.SpawnStruct("DecodedRecipient", []schema.StructField{ schema.SpawnStructField("header", "Any", true, false), schema.SpawnStructField("encrypted_key", "Base64Url", true, false), }, schema.SpawnStructRepresentationMap(nil))) - ts.Accumulate(schema.SpawnList("Recipients", "Recipient", false)) + ts.Accumulate(schema.SpawnList("DecodedRecipients", "DecodedRecipient", false)) // JOSE - ts.Accumulate(schema.SpawnStruct("JOSE", []schema.StructField{ + ts.Accumulate(schema.SpawnStruct("DecodedJOSE", []schema.StructField{ schema.SpawnStructField("aad", "Base64Url", true, false), schema.SpawnStructField("ciphertext", "Base64Url", true, false), schema.SpawnStructField("iv", "Base64Url", true, false), @@ -78,12 +83,51 @@ func main() { schema.SpawnStructField("payload", "Base64Url", true, false), schema.SpawnStructField("protected", "Base64Url", true, false), - schema.SpawnStructField("recipients", "Recipients", true, false), - schema.SpawnStructField("signatures", "Signatures", true, false), + schema.SpawnStructField("recipients", "DecodedRecipients", true, false), + schema.SpawnStructField("signatures", "DecodedSignatures", true, false), schema.SpawnStructField("tag", "Base64Url", true, false), schema.SpawnStructField("unprotected", "Any", true, false), }, schema.SpawnStructRepresentationMap(nil))) + // -- Encode types --> + + // JWS + ts.Accumulate(schema.SpawnStruct("EncodedSignature", []schema.StructField{ + schema.SpawnStructField("header", "Any", true, false), + schema.SpawnStructField("protected", "Raw", true, false), + schema.SpawnStructField("signature", "Raw", false, false), + }, schema.SpawnStructRepresentationMap(nil))) + + ts.Accumulate(schema.SpawnList("EncodedSignatures", "EncodedSignature", false)) + + // JWE + ts.Accumulate(schema.SpawnStruct("EncodedRecipient", []schema.StructField{ + schema.SpawnStructField("header", "Any", true, false), + schema.SpawnStructField("encrypted_key", "Raw", true, false), + }, schema.SpawnStructRepresentationMap(nil))) + + ts.Accumulate(schema.SpawnList("EncodedRecipients", "EncodedRecipient", false)) + + // JOSE + ts.Accumulate(schema.SpawnStruct("EncodedJOSE", []schema.StructField{ + schema.SpawnStructField("aad", "Raw", true, false), + schema.SpawnStructField("ciphertext", "Raw", true, false), + schema.SpawnStructField("iv", "Raw", true, false), + + // `link` is not encoded as part of DAG-JOSE because it is not included in the DAG-JOSE spec but is included + // here in the schema because it is required during encoding/decoding to/from other encodings (e.g. DAG-JSON). + // If `link` is present during encode, it is validated against `payload` and then ignored. If `payload` is + // present during decode, `link` is added with contents matching `payload`. + schema.SpawnStructField("link", "Link", true, false), + + schema.SpawnStructField("payload", "Raw", true, false), + schema.SpawnStructField("protected", "Raw", true, false), + schema.SpawnStructField("recipients", "EncodedRecipients", true, false), + schema.SpawnStructField("signatures", "EncodedSignatures", true, false), + schema.SpawnStructField("tag", "Raw", true, false), + schema.SpawnStructField("unprotected", "Any", true, false), + }, schema.SpawnStructRepresentationMap(nil))) + if errs := ts.ValidateGraph(); errs != nil { for _, err := range errs { fmt.Printf("- %s\n", err) diff --git a/dagjose/ipldsch_satisfaction.go b/dagjose/ipldsch_satisfaction.go index afbd5fe..3667502 100644 --- a/dagjose/ipldsch_satisfaction.go +++ b/dagjose/ipldsch_satisfaction.go @@ -1279,741 +1279,6211 @@ var _ datamodel.Node = &_Bytes__Repr{} type _Bytes__ReprPrototype = _Bytes__Prototype type _Bytes__ReprAssembler = _Bytes__Assembler -func (n Float) Float() float64 { - return n.x +func (n _DecodedJOSE) FieldAad() MaybeBase64Url { + return &n.aad } -func (_Float__Prototype) FromFloat(v float64) (Float, error) { - n := _Float{v} - return &n, nil +func (n _DecodedJOSE) FieldCiphertext() MaybeBase64Url { + return &n.ciphertext +} +func (n _DecodedJOSE) FieldIv() MaybeBase64Url { + return &n.iv +} +func (n _DecodedJOSE) FieldLink() MaybeLink { + return &n.link +} +func (n _DecodedJOSE) FieldPayload() MaybeBase64Url { + return &n.payload +} +func (n _DecodedJOSE) FieldProtected() MaybeBase64Url { + return &n.protected +} +func (n _DecodedJOSE) FieldRecipients() MaybeDecodedRecipients { + return &n.recipients +} +func (n _DecodedJOSE) FieldSignatures() MaybeDecodedSignatures { + return &n.signatures +} +func (n _DecodedJOSE) FieldTag() MaybeBase64Url { + return &n.tag +} +func (n _DecodedJOSE) FieldUnprotected() MaybeAny { + return &n.unprotected } -type _Float__Maybe struct { +type _DecodedJOSE__Maybe struct { m schema.Maybe - v _Float + v DecodedJOSE } -type MaybeFloat = *_Float__Maybe +type MaybeDecodedJOSE = *_DecodedJOSE__Maybe -func (m MaybeFloat) IsNull() bool { +func (m MaybeDecodedJOSE) IsNull() bool { return m.m == schema.Maybe_Null } -func (m MaybeFloat) IsAbsent() bool { +func (m MaybeDecodedJOSE) IsAbsent() bool { return m.m == schema.Maybe_Absent } -func (m MaybeFloat) Exists() bool { +func (m MaybeDecodedJOSE) Exists() bool { return m.m == schema.Maybe_Value } -func (m MaybeFloat) AsNode() datamodel.Node { +func (m MaybeDecodedJOSE) AsNode() datamodel.Node { switch m.m { case schema.Maybe_Absent: return datamodel.Absent case schema.Maybe_Null: return datamodel.Null case schema.Maybe_Value: - return &m.v + return m.v default: panic("unreachable") } } -func (m MaybeFloat) Must() Float { +func (m MaybeDecodedJOSE) Must() DecodedJOSE { if !m.Exists() { panic("unbox of a maybe rejected") } - return &m.v + return m.v } -var _ datamodel.Node = (Float)(&_Float{}) -var _ schema.TypedNode = (Float)(&_Float{}) +var ( + fieldName__DecodedJOSE_Aad = _String{"aad"} + fieldName__DecodedJOSE_Ciphertext = _String{"ciphertext"} + fieldName__DecodedJOSE_Iv = _String{"iv"} + fieldName__DecodedJOSE_Link = _String{"link"} + fieldName__DecodedJOSE_Payload = _String{"payload"} + fieldName__DecodedJOSE_Protected = _String{"protected"} + fieldName__DecodedJOSE_Recipients = _String{"recipients"} + fieldName__DecodedJOSE_Signatures = _String{"signatures"} + fieldName__DecodedJOSE_Tag = _String{"tag"} + fieldName__DecodedJOSE_Unprotected = _String{"unprotected"} +) +var _ datamodel.Node = (DecodedJOSE)(&_DecodedJOSE{}) +var _ schema.TypedNode = (DecodedJOSE)(&_DecodedJOSE{}) -func (Float) Kind() datamodel.Kind { - return datamodel.Kind_Float +func (DecodedJOSE) Kind() datamodel.Kind { + return datamodel.Kind_Map } -func (Float) LookupByString(string) (datamodel.Node, error) { - return mixins.Float{TypeName: "dagjose.Float"}.LookupByString("") +func (n DecodedJOSE) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "aad": + if n.aad.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.aad.v, nil + case "ciphertext": + if n.ciphertext.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.ciphertext.v, nil + case "iv": + if n.iv.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.iv.v, nil + case "link": + if n.link.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.link.v, nil + case "payload": + if n.payload.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.payload.v, nil + case "protected": + if n.protected.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.protected.v, nil + case "recipients": + if n.recipients.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.recipients.v, nil + case "signatures": + if n.signatures.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.signatures.v, nil + case "tag": + if n.tag.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.tag.v, nil + case "unprotected": + if n.unprotected.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return n.unprotected.v, nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} + } } -func (Float) LookupByNode(datamodel.Node) (datamodel.Node, error) { - return mixins.Float{TypeName: "dagjose.Float"}.LookupByNode(nil) +func (n DecodedJOSE) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) } -func (Float) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Float{TypeName: "dagjose.Float"}.LookupByIndex(0) +func (DecodedJOSE) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE"}.LookupByIndex(0) } -func (Float) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - return mixins.Float{TypeName: "dagjose.Float"}.LookupBySegment(seg) +func (n DecodedJOSE) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) } -func (Float) MapIterator() datamodel.MapIterator { - return nil +func (n DecodedJOSE) MapIterator() datamodel.MapIterator { + return &_DecodedJOSE__MapItr{n, 0} } -func (Float) ListIterator() datamodel.ListIterator { + +type _DecodedJOSE__MapItr struct { + n DecodedJOSE + idx int +} + +func (itr *_DecodedJOSE__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { + if itr.idx >= 10 { + return nil, nil, datamodel.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__DecodedJOSE_Aad + if itr.n.aad.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.aad.v + case 1: + k = &fieldName__DecodedJOSE_Ciphertext + if itr.n.ciphertext.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.ciphertext.v + case 2: + k = &fieldName__DecodedJOSE_Iv + if itr.n.iv.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.iv.v + case 3: + k = &fieldName__DecodedJOSE_Link + if itr.n.link.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.link.v + case 4: + k = &fieldName__DecodedJOSE_Payload + if itr.n.payload.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.payload.v + case 5: + k = &fieldName__DecodedJOSE_Protected + if itr.n.protected.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.protected.v + case 6: + k = &fieldName__DecodedJOSE_Recipients + if itr.n.recipients.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.recipients.v + case 7: + k = &fieldName__DecodedJOSE_Signatures + if itr.n.signatures.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.signatures.v + case 8: + k = &fieldName__DecodedJOSE_Tag + if itr.n.tag.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.tag.v + case 9: + k = &fieldName__DecodedJOSE_Unprotected + if itr.n.unprotected.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = itr.n.unprotected.v + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_DecodedJOSE__MapItr) Done() bool { + return itr.idx >= 10 +} + +func (DecodedJOSE) ListIterator() datamodel.ListIterator { return nil } -func (Float) Length() int64 { - return -1 +func (DecodedJOSE) Length() int64 { + return 10 } -func (Float) IsAbsent() bool { +func (DecodedJOSE) IsAbsent() bool { return false } -func (Float) IsNull() bool { +func (DecodedJOSE) IsNull() bool { return false } -func (Float) AsBool() (bool, error) { - return mixins.Float{TypeName: "dagjose.Float"}.AsBool() +func (DecodedJOSE) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE"}.AsBool() } -func (Float) AsInt() (int64, error) { - return mixins.Float{TypeName: "dagjose.Float"}.AsInt() +func (DecodedJOSE) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE"}.AsInt() } -func (n Float) AsFloat() (float64, error) { - return n.x, nil +func (DecodedJOSE) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE"}.AsFloat() } -func (Float) AsString() (string, error) { - return mixins.Float{TypeName: "dagjose.Float"}.AsString() +func (DecodedJOSE) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE"}.AsString() } -func (Float) AsBytes() ([]byte, error) { - return mixins.Float{TypeName: "dagjose.Float"}.AsBytes() +func (DecodedJOSE) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE"}.AsBytes() } -func (Float) AsLink() (datamodel.Link, error) { - return mixins.Float{TypeName: "dagjose.Float"}.AsLink() +func (DecodedJOSE) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE"}.AsLink() } -func (Float) Prototype() datamodel.NodePrototype { - return _Float__Prototype{} +func (DecodedJOSE) Prototype() datamodel.NodePrototype { + return _DecodedJOSE__Prototype{} } -type _Float__Prototype struct{} +type _DecodedJOSE__Prototype struct{} -func (_Float__Prototype) NewBuilder() datamodel.NodeBuilder { - var nb _Float__Builder +func (_DecodedJOSE__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _DecodedJOSE__Builder nb.Reset() return &nb } -type _Float__Builder struct { - _Float__Assembler +type _DecodedJOSE__Builder struct { + _DecodedJOSE__Assembler } -func (nb *_Float__Builder) Build() datamodel.Node { +func (nb *_DecodedJOSE__Builder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Float__Builder) Reset() { - var w _Float +func (nb *_DecodedJOSE__Builder) Reset() { + var w _DecodedJOSE var m schema.Maybe - *nb = _Float__Builder{_Float__Assembler{w: &w, m: &m}} + *nb = _DecodedJOSE__Builder{_DecodedJOSE__Assembler{w: &w, m: &m}} } -type _Float__Assembler struct { - w *_Float - m *schema.Maybe -} +type _DecodedJOSE__Assembler struct { + w *_DecodedJOSE + m *schema.Maybe + state maState + s int + f int -func (na *_Float__Assembler) reset() {} -func (_Float__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.FloatAssembler{TypeName: "dagjose.Float"}.BeginMap(0) + cm schema.Maybe + ca_aad _Base64Url__Assembler + ca_ciphertext _Base64Url__Assembler + ca_iv _Base64Url__Assembler + ca_link _Link__Assembler + ca_payload _Base64Url__Assembler + ca_protected _Base64Url__Assembler + ca_recipients _DecodedRecipients__Assembler + ca_signatures _DecodedSignatures__Assembler + ca_tag _Base64Url__Assembler + ca_unprotected _Any__Assembler } -func (_Float__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.FloatAssembler{TypeName: "dagjose.Float"}.BeginList(0) + +func (na *_DecodedJOSE__Assembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_aad.reset() + na.ca_ciphertext.reset() + na.ca_iv.reset() + na.ca_link.reset() + na.ca_payload.reset() + na.ca_protected.reset() + na.ca_recipients.reset() + na.ca_signatures.reset() + na.ca_tag.reset() + na.ca_unprotected.reset() } -func (na *_Float__Assembler) AssignNull() error { - switch *na.m { - case allowNull: + +var ( + fieldBit__DecodedJOSE_Aad = 1 << 0 + fieldBit__DecodedJOSE_Ciphertext = 1 << 1 + fieldBit__DecodedJOSE_Iv = 1 << 2 + fieldBit__DecodedJOSE_Link = 1 << 3 + fieldBit__DecodedJOSE_Payload = 1 << 4 + fieldBit__DecodedJOSE_Protected = 1 << 5 + fieldBit__DecodedJOSE_Recipients = 1 << 6 + fieldBit__DecodedJOSE_Signatures = 1 << 7 + fieldBit__DecodedJOSE_Tag = 1 << 8 + fieldBit__DecodedJOSE_Unprotected = 1 << 9 + fieldBits__DecodedJOSE_sufficient = 0 +) + +func (na *_DecodedJOSE__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_DecodedJOSE{} + } + return na, nil +} +func (_DecodedJOSE__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE"}.BeginList(0) +} +func (na *_DecodedJOSE__Assembler) AssignNull() error { + switch *na.m { + case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignNull() + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } panic("unreachable") } -func (_Float__Assembler) AssignBool(bool) error { - return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignBool(false) +func (_DecodedJOSE__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE"}.AssignBool(false) } -func (_Float__Assembler) AssignInt(int64) error { - return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignInt(0) +func (_DecodedJOSE__Assembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE"}.AssignInt(0) } -func (na *_Float__Assembler) AssignFloat(v float64) error { - switch *na.m { - case schema.Maybe_Value, schema.Maybe_Null: - panic("invalid state: cannot assign into assembler that's already finished") - } - na.w.x = v - *na.m = schema.Maybe_Value - return nil +func (_DecodedJOSE__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE"}.AssignFloat(0) } -func (_Float__Assembler) AssignString(string) error { - return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignString("") +func (_DecodedJOSE__Assembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE"}.AssignString("") } -func (_Float__Assembler) AssignBytes([]byte) error { - return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignBytes(nil) +func (_DecodedJOSE__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE"}.AssignBytes(nil) } -func (_Float__Assembler) AssignLink(datamodel.Link) error { - return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignLink(nil) +func (_DecodedJOSE__Assembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE"}.AssignLink(nil) } -func (na *_Float__Assembler) AssignNode(v datamodel.Node) error { +func (na *_DecodedJOSE__Assembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Float); ok { + if v2, ok := v.(*_DecodedJOSE); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil } *na.w = *v2 *na.m = schema.Maybe_Value return nil } - if v2, err := v.AsFloat(); err != nil { - return err - } else { - return na.AssignFloat(v2) + if v.Kind() != datamodel.Kind_Map { + return datamodel.ErrWrongKind{TypeName: "dagjose.DecodedJOSE", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() } -func (_Float__Assembler) Prototype() datamodel.NodePrototype { - return _Float__Prototype{} -} -func (Float) Type() schema.Type { - return nil /*TODO:typelit*/ -} -func (n Float) Representation() datamodel.Node { - return (*_Float__Repr)(n) -} - -type _Float__Repr = _Float - -var _ datamodel.Node = &_Float__Repr{} - -type _Float__ReprPrototype = _Float__Prototype -type _Float__ReprAssembler = _Float__Assembler - -func (n Int) Int() int64 { - return n.x -} -func (_Int__Prototype) FromInt(v int64) (Int, error) { - n := _Int{v} - return &n, nil -} - -type _Int__Maybe struct { - m schema.Maybe - v _Int -} -type MaybeInt = *_Int__Maybe - -func (m MaybeInt) IsNull() bool { - return m.m == schema.Maybe_Null -} -func (m MaybeInt) IsAbsent() bool { - return m.m == schema.Maybe_Absent -} -func (m MaybeInt) Exists() bool { - return m.m == schema.Maybe_Value +func (_DecodedJOSE__Assembler) Prototype() datamodel.NodePrototype { + return _DecodedJOSE__Prototype{} } -func (m MaybeInt) AsNode() datamodel.Node { - switch m.m { - case schema.Maybe_Absent: - return datamodel.Absent - case schema.Maybe_Null: - return datamodel.Null - case schema.Maybe_Value: - return &m.v +func (ma *_DecodedJOSE__Assembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.aad.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.ciphertext.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 2: + switch ma.w.iv.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 3: + switch ma.w.link.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 4: + switch ma.w.payload.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 5: + switch ma.w.protected.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 6: + switch ma.w.recipients.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 7: + switch ma.w.signatures.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 8: + switch ma.w.tag.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 9: + switch ma.w.unprotected.m { + case schema.Maybe_Value: + ma.w.unprotected.v = ma.ca_unprotected.w + ma.state = maState_initial + return true + default: + return false + } default: panic("unreachable") } } -func (m MaybeInt) Must() Int { - if !m.Exists() { - panic("unbox of a maybe rejected") +func (ma *_DecodedJOSE__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") } - return &m.v -} - -var _ datamodel.Node = (Int)(&_Int{}) -var _ schema.TypedNode = (Int)(&_Int{}) - -func (Int) Kind() datamodel.Kind { - return datamodel.Kind_Int -} -func (Int) LookupByString(string) (datamodel.Node, error) { - return mixins.Int{TypeName: "dagjose.Int"}.LookupByString("") -} -func (Int) LookupByNode(datamodel.Node) (datamodel.Node, error) { - return mixins.Int{TypeName: "dagjose.Int"}.LookupByNode(nil) -} -func (Int) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Int{TypeName: "dagjose.Int"}.LookupByIndex(0) -} -func (Int) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - return mixins.Int{TypeName: "dagjose.Int"}.LookupBySegment(seg) -} -func (Int) MapIterator() datamodel.MapIterator { - return nil -} -func (Int) ListIterator() datamodel.ListIterator { - return nil -} -func (Int) Length() int64 { - return -1 -} -func (Int) IsAbsent() bool { - return false -} -func (Int) IsNull() bool { - return false -} -func (Int) AsBool() (bool, error) { - return mixins.Int{TypeName: "dagjose.Int"}.AsBool() -} -func (n Int) AsInt() (int64, error) { - return n.x, nil -} -func (Int) AsFloat() (float64, error) { - return mixins.Int{TypeName: "dagjose.Int"}.AsFloat() + switch k { + case "aad": + if ma.s&fieldBit__DecodedJOSE_Aad != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Aad} + } + ma.s += fieldBit__DecodedJOSE_Aad + ma.state = maState_midValue + ma.f = 0 + ma.ca_aad.w = &ma.w.aad.v + ma.ca_aad.m = &ma.w.aad.m + return &ma.ca_aad, nil + case "ciphertext": + if ma.s&fieldBit__DecodedJOSE_Ciphertext != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Ciphertext} + } + ma.s += fieldBit__DecodedJOSE_Ciphertext + ma.state = maState_midValue + ma.f = 1 + ma.ca_ciphertext.w = &ma.w.ciphertext.v + ma.ca_ciphertext.m = &ma.w.ciphertext.m + return &ma.ca_ciphertext, nil + case "iv": + if ma.s&fieldBit__DecodedJOSE_Iv != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Iv} + } + ma.s += fieldBit__DecodedJOSE_Iv + ma.state = maState_midValue + ma.f = 2 + ma.ca_iv.w = &ma.w.iv.v + ma.ca_iv.m = &ma.w.iv.m + return &ma.ca_iv, nil + case "link": + if ma.s&fieldBit__DecodedJOSE_Link != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Link} + } + ma.s += fieldBit__DecodedJOSE_Link + ma.state = maState_midValue + ma.f = 3 + ma.ca_link.w = &ma.w.link.v + ma.ca_link.m = &ma.w.link.m + return &ma.ca_link, nil + case "payload": + if ma.s&fieldBit__DecodedJOSE_Payload != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Payload} + } + ma.s += fieldBit__DecodedJOSE_Payload + ma.state = maState_midValue + ma.f = 4 + ma.ca_payload.w = &ma.w.payload.v + ma.ca_payload.m = &ma.w.payload.m + return &ma.ca_payload, nil + case "protected": + if ma.s&fieldBit__DecodedJOSE_Protected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Protected} + } + ma.s += fieldBit__DecodedJOSE_Protected + ma.state = maState_midValue + ma.f = 5 + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + return &ma.ca_protected, nil + case "recipients": + if ma.s&fieldBit__DecodedJOSE_Recipients != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Recipients} + } + ma.s += fieldBit__DecodedJOSE_Recipients + ma.state = maState_midValue + ma.f = 6 + ma.ca_recipients.w = &ma.w.recipients.v + ma.ca_recipients.m = &ma.w.recipients.m + return &ma.ca_recipients, nil + case "signatures": + if ma.s&fieldBit__DecodedJOSE_Signatures != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Signatures} + } + ma.s += fieldBit__DecodedJOSE_Signatures + ma.state = maState_midValue + ma.f = 7 + ma.ca_signatures.w = &ma.w.signatures.v + ma.ca_signatures.m = &ma.w.signatures.m + return &ma.ca_signatures, nil + case "tag": + if ma.s&fieldBit__DecodedJOSE_Tag != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Tag} + } + ma.s += fieldBit__DecodedJOSE_Tag + ma.state = maState_midValue + ma.f = 8 + ma.ca_tag.w = &ma.w.tag.v + ma.ca_tag.m = &ma.w.tag.m + return &ma.ca_tag, nil + case "unprotected": + if ma.s&fieldBit__DecodedJOSE_Unprotected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Unprotected} + } + ma.s += fieldBit__DecodedJOSE_Unprotected + ma.state = maState_midValue + ma.f = 9 + ma.ca_unprotected.w = ma.w.unprotected.v + ma.ca_unprotected.m = &ma.w.unprotected.m + return &ma.ca_unprotected, nil + } + return nil, schema.ErrInvalidKey{TypeName: "dagjose.DecodedJOSE", Key: &_String{k}} +} +func (ma *_DecodedJOSE__Assembler) AssembleKey() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_DecodedJOSE__KeyAssembler)(ma) +} +func (ma *_DecodedJOSE__Assembler) AssembleValue() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_aad.w = &ma.w.aad.v + ma.ca_aad.m = &ma.w.aad.m + return &ma.ca_aad + case 1: + ma.ca_ciphertext.w = &ma.w.ciphertext.v + ma.ca_ciphertext.m = &ma.w.ciphertext.m + return &ma.ca_ciphertext + case 2: + ma.ca_iv.w = &ma.w.iv.v + ma.ca_iv.m = &ma.w.iv.m + return &ma.ca_iv + case 3: + ma.ca_link.w = &ma.w.link.v + ma.ca_link.m = &ma.w.link.m + return &ma.ca_link + case 4: + ma.ca_payload.w = &ma.w.payload.v + ma.ca_payload.m = &ma.w.payload.m + return &ma.ca_payload + case 5: + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + return &ma.ca_protected + case 6: + ma.ca_recipients.w = &ma.w.recipients.v + ma.ca_recipients.m = &ma.w.recipients.m + return &ma.ca_recipients + case 7: + ma.ca_signatures.w = &ma.w.signatures.v + ma.ca_signatures.m = &ma.w.signatures.m + return &ma.ca_signatures + case 8: + ma.ca_tag.w = &ma.w.tag.v + ma.ca_tag.m = &ma.w.tag.m + return &ma.ca_tag + case 9: + ma.ca_unprotected.w = ma.w.unprotected.v + ma.ca_unprotected.m = &ma.w.unprotected.m + return &ma.ca_unprotected + default: + panic("unreachable") + } +} +func (ma *_DecodedJOSE__Assembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__DecodedJOSE_sufficient != fieldBits__DecodedJOSE_sufficient { + err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_DecodedJOSE__Assembler) KeyPrototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (ma *_DecodedJOSE__Assembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler valueprototype") +} + +type _DecodedJOSE__KeyAssembler _DecodedJOSE__Assembler + +func (_DecodedJOSE__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.KeyAssembler"}.BeginMap(0) +} +func (_DecodedJOSE__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.KeyAssembler"}.BeginList(0) +} +func (na *_DecodedJOSE__KeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.KeyAssembler"}.AssignNull() +} +func (_DecodedJOSE__KeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.KeyAssembler"}.AssignBool(false) +} +func (_DecodedJOSE__KeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.KeyAssembler"}.AssignInt(0) +} +func (_DecodedJOSE__KeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.KeyAssembler"}.AssignFloat(0) +} +func (ka *_DecodedJOSE__KeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "aad": + if ka.s&fieldBit__DecodedJOSE_Aad != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Aad} + } + ka.s += fieldBit__DecodedJOSE_Aad + ka.state = maState_expectValue + ka.f = 0 + return nil + case "ciphertext": + if ka.s&fieldBit__DecodedJOSE_Ciphertext != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Ciphertext} + } + ka.s += fieldBit__DecodedJOSE_Ciphertext + ka.state = maState_expectValue + ka.f = 1 + return nil + case "iv": + if ka.s&fieldBit__DecodedJOSE_Iv != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Iv} + } + ka.s += fieldBit__DecodedJOSE_Iv + ka.state = maState_expectValue + ka.f = 2 + return nil + case "link": + if ka.s&fieldBit__DecodedJOSE_Link != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Link} + } + ka.s += fieldBit__DecodedJOSE_Link + ka.state = maState_expectValue + ka.f = 3 + return nil + case "payload": + if ka.s&fieldBit__DecodedJOSE_Payload != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Payload} + } + ka.s += fieldBit__DecodedJOSE_Payload + ka.state = maState_expectValue + ka.f = 4 + return nil + case "protected": + if ka.s&fieldBit__DecodedJOSE_Protected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Protected} + } + ka.s += fieldBit__DecodedJOSE_Protected + ka.state = maState_expectValue + ka.f = 5 + return nil + case "recipients": + if ka.s&fieldBit__DecodedJOSE_Recipients != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Recipients} + } + ka.s += fieldBit__DecodedJOSE_Recipients + ka.state = maState_expectValue + ka.f = 6 + return nil + case "signatures": + if ka.s&fieldBit__DecodedJOSE_Signatures != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Signatures} + } + ka.s += fieldBit__DecodedJOSE_Signatures + ka.state = maState_expectValue + ka.f = 7 + return nil + case "tag": + if ka.s&fieldBit__DecodedJOSE_Tag != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Tag} + } + ka.s += fieldBit__DecodedJOSE_Tag + ka.state = maState_expectValue + ka.f = 8 + return nil + case "unprotected": + if ka.s&fieldBit__DecodedJOSE_Unprotected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Unprotected} + } + ka.s += fieldBit__DecodedJOSE_Unprotected + ka.state = maState_expectValue + ka.f = 9 + return nil + default: + return schema.ErrInvalidKey{TypeName: "dagjose.DecodedJOSE", Key: &_String{k}} + } +} +func (_DecodedJOSE__KeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.KeyAssembler"}.AssignBytes(nil) +} +func (_DecodedJOSE__KeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.KeyAssembler"}.AssignLink(nil) +} +func (ka *_DecodedJOSE__KeyAssembler) AssignNode(v datamodel.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_DecodedJOSE__KeyAssembler) Prototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (DecodedJOSE) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n DecodedJOSE) Representation() datamodel.Node { + return (*_DecodedJOSE__Repr)(n) +} + +type _DecodedJOSE__Repr _DecodedJOSE + +var ( + fieldName__DecodedJOSE_Aad_serial = _String{"aad"} + fieldName__DecodedJOSE_Ciphertext_serial = _String{"ciphertext"} + fieldName__DecodedJOSE_Iv_serial = _String{"iv"} + fieldName__DecodedJOSE_Link_serial = _String{"link"} + fieldName__DecodedJOSE_Payload_serial = _String{"payload"} + fieldName__DecodedJOSE_Protected_serial = _String{"protected"} + fieldName__DecodedJOSE_Recipients_serial = _String{"recipients"} + fieldName__DecodedJOSE_Signatures_serial = _String{"signatures"} + fieldName__DecodedJOSE_Tag_serial = _String{"tag"} + fieldName__DecodedJOSE_Unprotected_serial = _String{"unprotected"} +) +var _ datamodel.Node = &_DecodedJOSE__Repr{} + +func (_DecodedJOSE__Repr) Kind() datamodel.Kind { + return datamodel.Kind_Map +} +func (n *_DecodedJOSE__Repr) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "aad": + if n.aad.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.aad.v.Representation(), nil + case "ciphertext": + if n.ciphertext.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.ciphertext.v.Representation(), nil + case "iv": + if n.iv.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.iv.v.Representation(), nil + case "link": + if n.link.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.link.v.Representation(), nil + case "payload": + if n.payload.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.payload.v.Representation(), nil + case "protected": + if n.protected.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.protected.v.Representation(), nil + case "recipients": + if n.recipients.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.recipients.v.Representation(), nil + case "signatures": + if n.signatures.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.signatures.v.Representation(), nil + case "tag": + if n.tag.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.tag.v.Representation(), nil + case "unprotected": + if n.unprotected.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.unprotected.v.Representation(), nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} + } +} +func (n *_DecodedJOSE__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (_DecodedJOSE__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE.Repr"}.LookupByIndex(0) +} +func (n _DecodedJOSE__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) +} +func (n *_DecodedJOSE__Repr) MapIterator() datamodel.MapIterator { + end := 10 + if n.unprotected.m == schema.Maybe_Absent { + end = 9 + } else { + goto done + } + if n.tag.m == schema.Maybe_Absent { + end = 8 + } else { + goto done + } + if n.signatures.m == schema.Maybe_Absent { + end = 7 + } else { + goto done + } + if n.recipients.m == schema.Maybe_Absent { + end = 6 + } else { + goto done + } + if n.protected.m == schema.Maybe_Absent { + end = 5 + } else { + goto done + } + if n.payload.m == schema.Maybe_Absent { + end = 4 + } else { + goto done + } + if n.link.m == schema.Maybe_Absent { + end = 3 + } else { + goto done + } + if n.iv.m == schema.Maybe_Absent { + end = 2 + } else { + goto done + } + if n.ciphertext.m == schema.Maybe_Absent { + end = 1 + } else { + goto done + } + if n.aad.m == schema.Maybe_Absent { + end = 0 + } else { + goto done + } +done: + return &_DecodedJOSE__ReprMapItr{n, 0, end} +} + +type _DecodedJOSE__ReprMapItr struct { + n *_DecodedJOSE__Repr + idx int + end int +} + +func (itr *_DecodedJOSE__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { +advance: + if itr.idx >= 10 { + return nil, nil, datamodel.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__DecodedJOSE_Aad_serial + if itr.n.aad.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.aad.v.Representation() + case 1: + k = &fieldName__DecodedJOSE_Ciphertext_serial + if itr.n.ciphertext.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.ciphertext.v.Representation() + case 2: + k = &fieldName__DecodedJOSE_Iv_serial + if itr.n.iv.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.iv.v.Representation() + case 3: + k = &fieldName__DecodedJOSE_Link_serial + if itr.n.link.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.link.v.Representation() + case 4: + k = &fieldName__DecodedJOSE_Payload_serial + if itr.n.payload.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.payload.v.Representation() + case 5: + k = &fieldName__DecodedJOSE_Protected_serial + if itr.n.protected.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.protected.v.Representation() + case 6: + k = &fieldName__DecodedJOSE_Recipients_serial + if itr.n.recipients.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.recipients.v.Representation() + case 7: + k = &fieldName__DecodedJOSE_Signatures_serial + if itr.n.signatures.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.signatures.v.Representation() + case 8: + k = &fieldName__DecodedJOSE_Tag_serial + if itr.n.tag.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.tag.v.Representation() + case 9: + k = &fieldName__DecodedJOSE_Unprotected_serial + if itr.n.unprotected.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.unprotected.v.Representation() + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_DecodedJOSE__ReprMapItr) Done() bool { + return itr.idx >= itr.end +} +func (_DecodedJOSE__Repr) ListIterator() datamodel.ListIterator { + return nil +} +func (rn *_DecodedJOSE__Repr) Length() int64 { + l := 10 + if rn.aad.m == schema.Maybe_Absent { + l-- + } + if rn.ciphertext.m == schema.Maybe_Absent { + l-- + } + if rn.iv.m == schema.Maybe_Absent { + l-- + } + if rn.link.m == schema.Maybe_Absent { + l-- + } + if rn.payload.m == schema.Maybe_Absent { + l-- + } + if rn.protected.m == schema.Maybe_Absent { + l-- + } + if rn.recipients.m == schema.Maybe_Absent { + l-- + } + if rn.signatures.m == schema.Maybe_Absent { + l-- + } + if rn.tag.m == schema.Maybe_Absent { + l-- + } + if rn.unprotected.m == schema.Maybe_Absent { + l-- + } + return int64(l) +} +func (_DecodedJOSE__Repr) IsAbsent() bool { + return false +} +func (_DecodedJOSE__Repr) IsNull() bool { + return false +} +func (_DecodedJOSE__Repr) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE.Repr"}.AsBool() +} +func (_DecodedJOSE__Repr) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE.Repr"}.AsInt() +} +func (_DecodedJOSE__Repr) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE.Repr"}.AsFloat() +} +func (_DecodedJOSE__Repr) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE.Repr"}.AsString() +} +func (_DecodedJOSE__Repr) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE.Repr"}.AsBytes() +} +func (_DecodedJOSE__Repr) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.DecodedJOSE.Repr"}.AsLink() +} +func (_DecodedJOSE__Repr) Prototype() datamodel.NodePrototype { + return _DecodedJOSE__ReprPrototype{} +} + +type _DecodedJOSE__ReprPrototype struct{} + +func (_DecodedJOSE__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _DecodedJOSE__ReprBuilder + nb.Reset() + return &nb +} + +type _DecodedJOSE__ReprBuilder struct { + _DecodedJOSE__ReprAssembler +} + +func (nb *_DecodedJOSE__ReprBuilder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_DecodedJOSE__ReprBuilder) Reset() { + var w _DecodedJOSE + var m schema.Maybe + *nb = _DecodedJOSE__ReprBuilder{_DecodedJOSE__ReprAssembler{w: &w, m: &m}} +} + +type _DecodedJOSE__ReprAssembler struct { + w *_DecodedJOSE + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_aad _Base64Url__ReprAssembler + ca_ciphertext _Base64Url__ReprAssembler + ca_iv _Base64Url__ReprAssembler + ca_link _Link__ReprAssembler + ca_payload _Base64Url__ReprAssembler + ca_protected _Base64Url__ReprAssembler + ca_recipients _DecodedRecipients__ReprAssembler + ca_signatures _DecodedSignatures__ReprAssembler + ca_tag _Base64Url__ReprAssembler + ca_unprotected _Any__ReprAssembler +} + +func (na *_DecodedJOSE__ReprAssembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_aad.reset() + na.ca_ciphertext.reset() + na.ca_iv.reset() + na.ca_link.reset() + na.ca_payload.reset() + na.ca_protected.reset() + na.ca_recipients.reset() + na.ca_signatures.reset() + na.ca_tag.reset() + na.ca_unprotected.reset() +} +func (na *_DecodedJOSE__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_DecodedJOSE{} + } + return na, nil +} +func (_DecodedJOSE__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE.Repr"}.BeginList(0) +} +func (na *_DecodedJOSE__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_DecodedJOSE__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE.Repr"}.AssignBool(false) +} +func (_DecodedJOSE__ReprAssembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE.Repr"}.AssignInt(0) +} +func (_DecodedJOSE__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE.Repr"}.AssignFloat(0) +} +func (_DecodedJOSE__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE.Repr"}.AssignString("") +} +func (_DecodedJOSE__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE.Repr"}.AssignBytes(nil) +} +func (_DecodedJOSE__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedJOSE.Repr"}.AssignLink(nil) +} +func (na *_DecodedJOSE__ReprAssembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_DecodedJOSE); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != datamodel.Kind_Map { + return datamodel.ErrWrongKind{TypeName: "dagjose.DecodedJOSE.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_DecodedJOSE__ReprAssembler) Prototype() datamodel.NodePrototype { + return _DecodedJOSE__ReprPrototype{} +} +func (ma *_DecodedJOSE__ReprAssembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.aad.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.ciphertext.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 2: + switch ma.w.iv.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 3: + switch ma.w.link.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 4: + switch ma.w.payload.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 5: + switch ma.w.protected.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 6: + switch ma.w.recipients.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 7: + switch ma.w.signatures.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 8: + switch ma.w.tag.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 9: + switch ma.w.unprotected.m { + case schema.Maybe_Value: + ma.w.unprotected.v = ma.ca_unprotected.w + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_DecodedJOSE__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "aad": + if ma.s&fieldBit__DecodedJOSE_Aad != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Aad_serial} + } + ma.s += fieldBit__DecodedJOSE_Aad + ma.state = maState_midValue + ma.f = 0 + ma.ca_aad.w = &ma.w.aad.v + ma.ca_aad.m = &ma.w.aad.m + + return &ma.ca_aad, nil + case "ciphertext": + if ma.s&fieldBit__DecodedJOSE_Ciphertext != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Ciphertext_serial} + } + ma.s += fieldBit__DecodedJOSE_Ciphertext + ma.state = maState_midValue + ma.f = 1 + ma.ca_ciphertext.w = &ma.w.ciphertext.v + ma.ca_ciphertext.m = &ma.w.ciphertext.m + + return &ma.ca_ciphertext, nil + case "iv": + if ma.s&fieldBit__DecodedJOSE_Iv != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Iv_serial} + } + ma.s += fieldBit__DecodedJOSE_Iv + ma.state = maState_midValue + ma.f = 2 + ma.ca_iv.w = &ma.w.iv.v + ma.ca_iv.m = &ma.w.iv.m + + return &ma.ca_iv, nil + case "link": + if ma.s&fieldBit__DecodedJOSE_Link != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Link_serial} + } + ma.s += fieldBit__DecodedJOSE_Link + ma.state = maState_midValue + ma.f = 3 + ma.ca_link.w = &ma.w.link.v + ma.ca_link.m = &ma.w.link.m + + return &ma.ca_link, nil + case "payload": + if ma.s&fieldBit__DecodedJOSE_Payload != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Payload_serial} + } + ma.s += fieldBit__DecodedJOSE_Payload + ma.state = maState_midValue + ma.f = 4 + ma.ca_payload.w = &ma.w.payload.v + ma.ca_payload.m = &ma.w.payload.m + + return &ma.ca_payload, nil + case "protected": + if ma.s&fieldBit__DecodedJOSE_Protected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Protected_serial} + } + ma.s += fieldBit__DecodedJOSE_Protected + ma.state = maState_midValue + ma.f = 5 + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + + return &ma.ca_protected, nil + case "recipients": + if ma.s&fieldBit__DecodedJOSE_Recipients != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Recipients_serial} + } + ma.s += fieldBit__DecodedJOSE_Recipients + ma.state = maState_midValue + ma.f = 6 + ma.ca_recipients.w = &ma.w.recipients.v + ma.ca_recipients.m = &ma.w.recipients.m + + return &ma.ca_recipients, nil + case "signatures": + if ma.s&fieldBit__DecodedJOSE_Signatures != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Signatures_serial} + } + ma.s += fieldBit__DecodedJOSE_Signatures + ma.state = maState_midValue + ma.f = 7 + ma.ca_signatures.w = &ma.w.signatures.v + ma.ca_signatures.m = &ma.w.signatures.m + + return &ma.ca_signatures, nil + case "tag": + if ma.s&fieldBit__DecodedJOSE_Tag != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Tag_serial} + } + ma.s += fieldBit__DecodedJOSE_Tag + ma.state = maState_midValue + ma.f = 8 + ma.ca_tag.w = &ma.w.tag.v + ma.ca_tag.m = &ma.w.tag.m + + return &ma.ca_tag, nil + case "unprotected": + if ma.s&fieldBit__DecodedJOSE_Unprotected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Unprotected_serial} + } + ma.s += fieldBit__DecodedJOSE_Unprotected + ma.state = maState_midValue + ma.f = 9 + ma.ca_unprotected.w = ma.w.unprotected.v + ma.ca_unprotected.m = &ma.w.unprotected.m + + return &ma.ca_unprotected, nil + default: + } + return nil, schema.ErrInvalidKey{TypeName: "dagjose.DecodedJOSE.Repr", Key: &_String{k}} +} +func (ma *_DecodedJOSE__ReprAssembler) AssembleKey() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_DecodedJOSE__ReprKeyAssembler)(ma) +} +func (ma *_DecodedJOSE__ReprAssembler) AssembleValue() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_aad.w = &ma.w.aad.v + ma.ca_aad.m = &ma.w.aad.m + + return &ma.ca_aad + case 1: + ma.ca_ciphertext.w = &ma.w.ciphertext.v + ma.ca_ciphertext.m = &ma.w.ciphertext.m + + return &ma.ca_ciphertext + case 2: + ma.ca_iv.w = &ma.w.iv.v + ma.ca_iv.m = &ma.w.iv.m + + return &ma.ca_iv + case 3: + ma.ca_link.w = &ma.w.link.v + ma.ca_link.m = &ma.w.link.m + + return &ma.ca_link + case 4: + ma.ca_payload.w = &ma.w.payload.v + ma.ca_payload.m = &ma.w.payload.m + + return &ma.ca_payload + case 5: + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + + return &ma.ca_protected + case 6: + ma.ca_recipients.w = &ma.w.recipients.v + ma.ca_recipients.m = &ma.w.recipients.m + + return &ma.ca_recipients + case 7: + ma.ca_signatures.w = &ma.w.signatures.v + ma.ca_signatures.m = &ma.w.signatures.m + + return &ma.ca_signatures + case 8: + ma.ca_tag.w = &ma.w.tag.v + ma.ca_tag.m = &ma.w.tag.m + + return &ma.ca_tag + case 9: + ma.ca_unprotected.w = ma.w.unprotected.v + ma.ca_unprotected.m = &ma.w.unprotected.m + + return &ma.ca_unprotected + default: + panic("unreachable") + } +} +func (ma *_DecodedJOSE__ReprAssembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__DecodedJOSE_sufficient != fieldBits__DecodedJOSE_sufficient { + err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_DecodedJOSE__ReprAssembler) KeyPrototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (ma *_DecodedJOSE__ReprAssembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler repr valueprototype") +} + +type _DecodedJOSE__ReprKeyAssembler _DecodedJOSE__ReprAssembler + +func (_DecodedJOSE__ReprKeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.Repr.KeyAssembler"}.BeginMap(0) +} +func (_DecodedJOSE__ReprKeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.Repr.KeyAssembler"}.BeginList(0) +} +func (na *_DecodedJOSE__ReprKeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.Repr.KeyAssembler"}.AssignNull() +} +func (_DecodedJOSE__ReprKeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.Repr.KeyAssembler"}.AssignBool(false) +} +func (_DecodedJOSE__ReprKeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.Repr.KeyAssembler"}.AssignInt(0) +} +func (_DecodedJOSE__ReprKeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.Repr.KeyAssembler"}.AssignFloat(0) +} +func (ka *_DecodedJOSE__ReprKeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "aad": + if ka.s&fieldBit__DecodedJOSE_Aad != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Aad_serial} + } + ka.s += fieldBit__DecodedJOSE_Aad + ka.state = maState_expectValue + ka.f = 0 + return nil + case "ciphertext": + if ka.s&fieldBit__DecodedJOSE_Ciphertext != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Ciphertext_serial} + } + ka.s += fieldBit__DecodedJOSE_Ciphertext + ka.state = maState_expectValue + ka.f = 1 + return nil + case "iv": + if ka.s&fieldBit__DecodedJOSE_Iv != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Iv_serial} + } + ka.s += fieldBit__DecodedJOSE_Iv + ka.state = maState_expectValue + ka.f = 2 + return nil + case "link": + if ka.s&fieldBit__DecodedJOSE_Link != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Link_serial} + } + ka.s += fieldBit__DecodedJOSE_Link + ka.state = maState_expectValue + ka.f = 3 + return nil + case "payload": + if ka.s&fieldBit__DecodedJOSE_Payload != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Payload_serial} + } + ka.s += fieldBit__DecodedJOSE_Payload + ka.state = maState_expectValue + ka.f = 4 + return nil + case "protected": + if ka.s&fieldBit__DecodedJOSE_Protected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Protected_serial} + } + ka.s += fieldBit__DecodedJOSE_Protected + ka.state = maState_expectValue + ka.f = 5 + return nil + case "recipients": + if ka.s&fieldBit__DecodedJOSE_Recipients != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Recipients_serial} + } + ka.s += fieldBit__DecodedJOSE_Recipients + ka.state = maState_expectValue + ka.f = 6 + return nil + case "signatures": + if ka.s&fieldBit__DecodedJOSE_Signatures != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Signatures_serial} + } + ka.s += fieldBit__DecodedJOSE_Signatures + ka.state = maState_expectValue + ka.f = 7 + return nil + case "tag": + if ka.s&fieldBit__DecodedJOSE_Tag != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Tag_serial} + } + ka.s += fieldBit__DecodedJOSE_Tag + ka.state = maState_expectValue + ka.f = 8 + return nil + case "unprotected": + if ka.s&fieldBit__DecodedJOSE_Unprotected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedJOSE_Unprotected_serial} + } + ka.s += fieldBit__DecodedJOSE_Unprotected + ka.state = maState_expectValue + ka.f = 9 + return nil + } + return schema.ErrInvalidKey{TypeName: "dagjose.DecodedJOSE.Repr", Key: &_String{k}} +} +func (_DecodedJOSE__ReprKeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.Repr.KeyAssembler"}.AssignBytes(nil) +} +func (_DecodedJOSE__ReprKeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedJOSE.Repr.KeyAssembler"}.AssignLink(nil) +} +func (ka *_DecodedJOSE__ReprKeyAssembler) AssignNode(v datamodel.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_DecodedJOSE__ReprKeyAssembler) Prototype() datamodel.NodePrototype { + return _String__Prototype{} +} + +func (n _DecodedRecipient) FieldHeader() MaybeAny { + return &n.header +} +func (n _DecodedRecipient) FieldEncrypted_key() MaybeBase64Url { + return &n.encrypted_key +} + +type _DecodedRecipient__Maybe struct { + m schema.Maybe + v DecodedRecipient +} +type MaybeDecodedRecipient = *_DecodedRecipient__Maybe + +func (m MaybeDecodedRecipient) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeDecodedRecipient) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeDecodedRecipient) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeDecodedRecipient) AsNode() datamodel.Node { + switch m.m { + case schema.Maybe_Absent: + return datamodel.Absent + case schema.Maybe_Null: + return datamodel.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeDecodedRecipient) Must() DecodedRecipient { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var ( + fieldName__DecodedRecipient_Header = _String{"header"} + fieldName__DecodedRecipient_Encrypted_key = _String{"encrypted_key"} +) +var _ datamodel.Node = (DecodedRecipient)(&_DecodedRecipient{}) +var _ schema.TypedNode = (DecodedRecipient)(&_DecodedRecipient{}) + +func (DecodedRecipient) Kind() datamodel.Kind { + return datamodel.Kind_Map +} +func (n DecodedRecipient) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "header": + if n.header.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return n.header.v, nil + case "encrypted_key": + if n.encrypted_key.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.encrypted_key.v, nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} + } +} +func (n DecodedRecipient) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (DecodedRecipient) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient"}.LookupByIndex(0) +} +func (n DecodedRecipient) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) +} +func (n DecodedRecipient) MapIterator() datamodel.MapIterator { + return &_DecodedRecipient__MapItr{n, 0} +} + +type _DecodedRecipient__MapItr struct { + n DecodedRecipient + idx int +} + +func (itr *_DecodedRecipient__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { + if itr.idx >= 2 { + return nil, nil, datamodel.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__DecodedRecipient_Header + if itr.n.header.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = itr.n.header.v + case 1: + k = &fieldName__DecodedRecipient_Encrypted_key + if itr.n.encrypted_key.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.encrypted_key.v + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_DecodedRecipient__MapItr) Done() bool { + return itr.idx >= 2 +} + +func (DecodedRecipient) ListIterator() datamodel.ListIterator { + return nil +} +func (DecodedRecipient) Length() int64 { + return 2 +} +func (DecodedRecipient) IsAbsent() bool { + return false +} +func (DecodedRecipient) IsNull() bool { + return false +} +func (DecodedRecipient) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient"}.AsBool() +} +func (DecodedRecipient) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient"}.AsInt() +} +func (DecodedRecipient) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient"}.AsFloat() +} +func (DecodedRecipient) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient"}.AsString() +} +func (DecodedRecipient) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient"}.AsBytes() +} +func (DecodedRecipient) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient"}.AsLink() +} +func (DecodedRecipient) Prototype() datamodel.NodePrototype { + return _DecodedRecipient__Prototype{} +} + +type _DecodedRecipient__Prototype struct{} + +func (_DecodedRecipient__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _DecodedRecipient__Builder + nb.Reset() + return &nb +} + +type _DecodedRecipient__Builder struct { + _DecodedRecipient__Assembler +} + +func (nb *_DecodedRecipient__Builder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_DecodedRecipient__Builder) Reset() { + var w _DecodedRecipient + var m schema.Maybe + *nb = _DecodedRecipient__Builder{_DecodedRecipient__Assembler{w: &w, m: &m}} +} + +type _DecodedRecipient__Assembler struct { + w *_DecodedRecipient + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_header _Any__Assembler + ca_encrypted_key _Base64Url__Assembler +} + +func (na *_DecodedRecipient__Assembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_header.reset() + na.ca_encrypted_key.reset() +} + +var ( + fieldBit__DecodedRecipient_Header = 1 << 0 + fieldBit__DecodedRecipient_Encrypted_key = 1 << 1 + fieldBits__DecodedRecipient_sufficient = 0 +) + +func (na *_DecodedRecipient__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_DecodedRecipient{} + } + return na, nil +} +func (_DecodedRecipient__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient"}.BeginList(0) +} +func (na *_DecodedRecipient__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_DecodedRecipient__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient"}.AssignBool(false) +} +func (_DecodedRecipient__Assembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient"}.AssignInt(0) +} +func (_DecodedRecipient__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient"}.AssignFloat(0) +} +func (_DecodedRecipient__Assembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient"}.AssignString("") +} +func (_DecodedRecipient__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient"}.AssignBytes(nil) +} +func (_DecodedRecipient__Assembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient"}.AssignLink(nil) +} +func (na *_DecodedRecipient__Assembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_DecodedRecipient); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != datamodel.Kind_Map { + return datamodel.ErrWrongKind{TypeName: "dagjose.DecodedRecipient", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_DecodedRecipient__Assembler) Prototype() datamodel.NodePrototype { + return _DecodedRecipient__Prototype{} +} +func (ma *_DecodedRecipient__Assembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.header.m { + case schema.Maybe_Value: + ma.w.header.v = ma.ca_header.w + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.encrypted_key.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_DecodedRecipient__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "header": + if ma.s&fieldBit__DecodedRecipient_Header != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedRecipient_Header} + } + ma.s += fieldBit__DecodedRecipient_Header + ma.state = maState_midValue + ma.f = 0 + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + return &ma.ca_header, nil + case "encrypted_key": + if ma.s&fieldBit__DecodedRecipient_Encrypted_key != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedRecipient_Encrypted_key} + } + ma.s += fieldBit__DecodedRecipient_Encrypted_key + ma.state = maState_midValue + ma.f = 1 + ma.ca_encrypted_key.w = &ma.w.encrypted_key.v + ma.ca_encrypted_key.m = &ma.w.encrypted_key.m + return &ma.ca_encrypted_key, nil + } + return nil, schema.ErrInvalidKey{TypeName: "dagjose.DecodedRecipient", Key: &_String{k}} +} +func (ma *_DecodedRecipient__Assembler) AssembleKey() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_DecodedRecipient__KeyAssembler)(ma) +} +func (ma *_DecodedRecipient__Assembler) AssembleValue() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + return &ma.ca_header + case 1: + ma.ca_encrypted_key.w = &ma.w.encrypted_key.v + ma.ca_encrypted_key.m = &ma.w.encrypted_key.m + return &ma.ca_encrypted_key + default: + panic("unreachable") + } +} +func (ma *_DecodedRecipient__Assembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__DecodedRecipient_sufficient != fieldBits__DecodedRecipient_sufficient { + err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_DecodedRecipient__Assembler) KeyPrototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (ma *_DecodedRecipient__Assembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler valueprototype") +} + +type _DecodedRecipient__KeyAssembler _DecodedRecipient__Assembler + +func (_DecodedRecipient__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.KeyAssembler"}.BeginMap(0) +} +func (_DecodedRecipient__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.KeyAssembler"}.BeginList(0) +} +func (na *_DecodedRecipient__KeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.KeyAssembler"}.AssignNull() +} +func (_DecodedRecipient__KeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.KeyAssembler"}.AssignBool(false) +} +func (_DecodedRecipient__KeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.KeyAssembler"}.AssignInt(0) +} +func (_DecodedRecipient__KeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.KeyAssembler"}.AssignFloat(0) +} +func (ka *_DecodedRecipient__KeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "header": + if ka.s&fieldBit__DecodedRecipient_Header != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedRecipient_Header} + } + ka.s += fieldBit__DecodedRecipient_Header + ka.state = maState_expectValue + ka.f = 0 + return nil + case "encrypted_key": + if ka.s&fieldBit__DecodedRecipient_Encrypted_key != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedRecipient_Encrypted_key} + } + ka.s += fieldBit__DecodedRecipient_Encrypted_key + ka.state = maState_expectValue + ka.f = 1 + return nil + default: + return schema.ErrInvalidKey{TypeName: "dagjose.DecodedRecipient", Key: &_String{k}} + } +} +func (_DecodedRecipient__KeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.KeyAssembler"}.AssignBytes(nil) +} +func (_DecodedRecipient__KeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.KeyAssembler"}.AssignLink(nil) +} +func (ka *_DecodedRecipient__KeyAssembler) AssignNode(v datamodel.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_DecodedRecipient__KeyAssembler) Prototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (DecodedRecipient) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n DecodedRecipient) Representation() datamodel.Node { + return (*_DecodedRecipient__Repr)(n) +} + +type _DecodedRecipient__Repr _DecodedRecipient + +var ( + fieldName__DecodedRecipient_Header_serial = _String{"header"} + fieldName__DecodedRecipient_Encrypted_key_serial = _String{"encrypted_key"} +) +var _ datamodel.Node = &_DecodedRecipient__Repr{} + +func (_DecodedRecipient__Repr) Kind() datamodel.Kind { + return datamodel.Kind_Map +} +func (n *_DecodedRecipient__Repr) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "header": + if n.header.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.header.v.Representation(), nil + case "encrypted_key": + if n.encrypted_key.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.encrypted_key.v.Representation(), nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} + } +} +func (n *_DecodedRecipient__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (_DecodedRecipient__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient.Repr"}.LookupByIndex(0) +} +func (n _DecodedRecipient__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) +} +func (n *_DecodedRecipient__Repr) MapIterator() datamodel.MapIterator { + end := 2 + if n.encrypted_key.m == schema.Maybe_Absent { + end = 1 + } else { + goto done + } + if n.header.m == schema.Maybe_Absent { + end = 0 + } else { + goto done + } +done: + return &_DecodedRecipient__ReprMapItr{n, 0, end} +} + +type _DecodedRecipient__ReprMapItr struct { + n *_DecodedRecipient__Repr + idx int + end int +} + +func (itr *_DecodedRecipient__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { +advance: + if itr.idx >= 2 { + return nil, nil, datamodel.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__DecodedRecipient_Header_serial + if itr.n.header.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.header.v.Representation() + case 1: + k = &fieldName__DecodedRecipient_Encrypted_key_serial + if itr.n.encrypted_key.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.encrypted_key.v.Representation() + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_DecodedRecipient__ReprMapItr) Done() bool { + return itr.idx >= itr.end +} +func (_DecodedRecipient__Repr) ListIterator() datamodel.ListIterator { + return nil +} +func (rn *_DecodedRecipient__Repr) Length() int64 { + l := 2 + if rn.header.m == schema.Maybe_Absent { + l-- + } + if rn.encrypted_key.m == schema.Maybe_Absent { + l-- + } + return int64(l) +} +func (_DecodedRecipient__Repr) IsAbsent() bool { + return false +} +func (_DecodedRecipient__Repr) IsNull() bool { + return false +} +func (_DecodedRecipient__Repr) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient.Repr"}.AsBool() +} +func (_DecodedRecipient__Repr) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient.Repr"}.AsInt() +} +func (_DecodedRecipient__Repr) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient.Repr"}.AsFloat() +} +func (_DecodedRecipient__Repr) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient.Repr"}.AsString() +} +func (_DecodedRecipient__Repr) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient.Repr"}.AsBytes() +} +func (_DecodedRecipient__Repr) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.DecodedRecipient.Repr"}.AsLink() +} +func (_DecodedRecipient__Repr) Prototype() datamodel.NodePrototype { + return _DecodedRecipient__ReprPrototype{} +} + +type _DecodedRecipient__ReprPrototype struct{} + +func (_DecodedRecipient__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _DecodedRecipient__ReprBuilder + nb.Reset() + return &nb +} + +type _DecodedRecipient__ReprBuilder struct { + _DecodedRecipient__ReprAssembler +} + +func (nb *_DecodedRecipient__ReprBuilder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_DecodedRecipient__ReprBuilder) Reset() { + var w _DecodedRecipient + var m schema.Maybe + *nb = _DecodedRecipient__ReprBuilder{_DecodedRecipient__ReprAssembler{w: &w, m: &m}} +} + +type _DecodedRecipient__ReprAssembler struct { + w *_DecodedRecipient + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_header _Any__ReprAssembler + ca_encrypted_key _Base64Url__ReprAssembler +} + +func (na *_DecodedRecipient__ReprAssembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_header.reset() + na.ca_encrypted_key.reset() +} +func (na *_DecodedRecipient__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_DecodedRecipient{} + } + return na, nil +} +func (_DecodedRecipient__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient.Repr"}.BeginList(0) +} +func (na *_DecodedRecipient__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_DecodedRecipient__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient.Repr"}.AssignBool(false) +} +func (_DecodedRecipient__ReprAssembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient.Repr"}.AssignInt(0) +} +func (_DecodedRecipient__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient.Repr"}.AssignFloat(0) +} +func (_DecodedRecipient__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient.Repr"}.AssignString("") +} +func (_DecodedRecipient__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient.Repr"}.AssignBytes(nil) +} +func (_DecodedRecipient__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedRecipient.Repr"}.AssignLink(nil) +} +func (na *_DecodedRecipient__ReprAssembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_DecodedRecipient); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != datamodel.Kind_Map { + return datamodel.ErrWrongKind{TypeName: "dagjose.DecodedRecipient.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_DecodedRecipient__ReprAssembler) Prototype() datamodel.NodePrototype { + return _DecodedRecipient__ReprPrototype{} +} +func (ma *_DecodedRecipient__ReprAssembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.header.m { + case schema.Maybe_Value: + ma.w.header.v = ma.ca_header.w + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.encrypted_key.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_DecodedRecipient__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "header": + if ma.s&fieldBit__DecodedRecipient_Header != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedRecipient_Header_serial} + } + ma.s += fieldBit__DecodedRecipient_Header + ma.state = maState_midValue + ma.f = 0 + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + + return &ma.ca_header, nil + case "encrypted_key": + if ma.s&fieldBit__DecodedRecipient_Encrypted_key != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedRecipient_Encrypted_key_serial} + } + ma.s += fieldBit__DecodedRecipient_Encrypted_key + ma.state = maState_midValue + ma.f = 1 + ma.ca_encrypted_key.w = &ma.w.encrypted_key.v + ma.ca_encrypted_key.m = &ma.w.encrypted_key.m + + return &ma.ca_encrypted_key, nil + default: + } + return nil, schema.ErrInvalidKey{TypeName: "dagjose.DecodedRecipient.Repr", Key: &_String{k}} +} +func (ma *_DecodedRecipient__ReprAssembler) AssembleKey() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_DecodedRecipient__ReprKeyAssembler)(ma) +} +func (ma *_DecodedRecipient__ReprAssembler) AssembleValue() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + + return &ma.ca_header + case 1: + ma.ca_encrypted_key.w = &ma.w.encrypted_key.v + ma.ca_encrypted_key.m = &ma.w.encrypted_key.m + + return &ma.ca_encrypted_key + default: + panic("unreachable") + } +} +func (ma *_DecodedRecipient__ReprAssembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__DecodedRecipient_sufficient != fieldBits__DecodedRecipient_sufficient { + err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_DecodedRecipient__ReprAssembler) KeyPrototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (ma *_DecodedRecipient__ReprAssembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler repr valueprototype") +} + +type _DecodedRecipient__ReprKeyAssembler _DecodedRecipient__ReprAssembler + +func (_DecodedRecipient__ReprKeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.Repr.KeyAssembler"}.BeginMap(0) +} +func (_DecodedRecipient__ReprKeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.Repr.KeyAssembler"}.BeginList(0) +} +func (na *_DecodedRecipient__ReprKeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.Repr.KeyAssembler"}.AssignNull() +} +func (_DecodedRecipient__ReprKeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.Repr.KeyAssembler"}.AssignBool(false) +} +func (_DecodedRecipient__ReprKeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.Repr.KeyAssembler"}.AssignInt(0) +} +func (_DecodedRecipient__ReprKeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.Repr.KeyAssembler"}.AssignFloat(0) +} +func (ka *_DecodedRecipient__ReprKeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "header": + if ka.s&fieldBit__DecodedRecipient_Header != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedRecipient_Header_serial} + } + ka.s += fieldBit__DecodedRecipient_Header + ka.state = maState_expectValue + ka.f = 0 + return nil + case "encrypted_key": + if ka.s&fieldBit__DecodedRecipient_Encrypted_key != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedRecipient_Encrypted_key_serial} + } + ka.s += fieldBit__DecodedRecipient_Encrypted_key + ka.state = maState_expectValue + ka.f = 1 + return nil + } + return schema.ErrInvalidKey{TypeName: "dagjose.DecodedRecipient.Repr", Key: &_String{k}} +} +func (_DecodedRecipient__ReprKeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.Repr.KeyAssembler"}.AssignBytes(nil) +} +func (_DecodedRecipient__ReprKeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedRecipient.Repr.KeyAssembler"}.AssignLink(nil) +} +func (ka *_DecodedRecipient__ReprKeyAssembler) AssignNode(v datamodel.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_DecodedRecipient__ReprKeyAssembler) Prototype() datamodel.NodePrototype { + return _String__Prototype{} +} + +func (n *_DecodedRecipients) Lookup(idx int64) DecodedRecipient { + if n.Length() <= idx { + return nil + } + v := &n.x[idx] + return v +} +func (n *_DecodedRecipients) LookupMaybe(idx int64) MaybeDecodedRecipient { + if n.Length() <= idx { + return nil + } + v := &n.x[idx] + return &_DecodedRecipient__Maybe{ + m: schema.Maybe_Value, + v: v, + } +} + +var _DecodedRecipients__valueAbsent = _DecodedRecipient__Maybe{m: schema.Maybe_Absent} + +func (n DecodedRecipients) Iterator() *DecodedRecipients__Itr { + return &DecodedRecipients__Itr{n, 0} +} + +type DecodedRecipients__Itr struct { + n DecodedRecipients + idx int +} + +func (itr *DecodedRecipients__Itr) Next() (idx int64, v DecodedRecipient) { + if itr.idx >= len(itr.n.x) { + return -1, nil + } + idx = int64(itr.idx) + v = &itr.n.x[itr.idx] + itr.idx++ + return +} +func (itr *DecodedRecipients__Itr) Done() bool { + return itr.idx >= len(itr.n.x) +} + +type _DecodedRecipients__Maybe struct { + m schema.Maybe + v _DecodedRecipients +} +type MaybeDecodedRecipients = *_DecodedRecipients__Maybe + +func (m MaybeDecodedRecipients) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeDecodedRecipients) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeDecodedRecipients) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeDecodedRecipients) AsNode() datamodel.Node { + switch m.m { + case schema.Maybe_Absent: + return datamodel.Absent + case schema.Maybe_Null: + return datamodel.Null + case schema.Maybe_Value: + return &m.v + default: + panic("unreachable") + } +} +func (m MaybeDecodedRecipients) Must() DecodedRecipients { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return &m.v +} + +var _ datamodel.Node = (DecodedRecipients)(&_DecodedRecipients{}) +var _ schema.TypedNode = (DecodedRecipients)(&_DecodedRecipients{}) + +func (DecodedRecipients) Kind() datamodel.Kind { + return datamodel.Kind_List +} +func (DecodedRecipients) LookupByString(string) (datamodel.Node, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients"}.LookupByString("") +} +func (n DecodedRecipients) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + idx, err := k.AsInt() + if err != nil { + return nil, err + } + return n.LookupByIndex(idx) +} +func (n DecodedRecipients) LookupByIndex(idx int64) (datamodel.Node, error) { + if n.Length() <= idx { + return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)} + } + v := &n.x[idx] + return v, nil +} +func (n DecodedRecipients) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.DecodedRecipients", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (DecodedRecipients) MapIterator() datamodel.MapIterator { + return nil +} +func (n DecodedRecipients) ListIterator() datamodel.ListIterator { + return &_DecodedRecipients__ListItr{n, 0} +} + +type _DecodedRecipients__ListItr struct { + n DecodedRecipients + idx int +} + +func (itr *_DecodedRecipients__ListItr) Next() (idx int64, v datamodel.Node, _ error) { + if itr.idx >= len(itr.n.x) { + return -1, nil, datamodel.ErrIteratorOverread{} + } + idx = int64(itr.idx) + x := &itr.n.x[itr.idx] + v = x + itr.idx++ + return +} +func (itr *_DecodedRecipients__ListItr) Done() bool { + return itr.idx >= len(itr.n.x) +} + +func (n DecodedRecipients) Length() int64 { + return int64(len(n.x)) +} +func (DecodedRecipients) IsAbsent() bool { + return false +} +func (DecodedRecipients) IsNull() bool { + return false +} +func (DecodedRecipients) AsBool() (bool, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients"}.AsBool() +} +func (DecodedRecipients) AsInt() (int64, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients"}.AsInt() +} +func (DecodedRecipients) AsFloat() (float64, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients"}.AsFloat() +} +func (DecodedRecipients) AsString() (string, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients"}.AsString() +} +func (DecodedRecipients) AsBytes() ([]byte, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients"}.AsBytes() +} +func (DecodedRecipients) AsLink() (datamodel.Link, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients"}.AsLink() +} +func (DecodedRecipients) Prototype() datamodel.NodePrototype { + return _DecodedRecipients__Prototype{} +} + +type _DecodedRecipients__Prototype struct{} + +func (_DecodedRecipients__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _DecodedRecipients__Builder + nb.Reset() + return &nb +} + +type _DecodedRecipients__Builder struct { + _DecodedRecipients__Assembler +} + +func (nb *_DecodedRecipients__Builder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_DecodedRecipients__Builder) Reset() { + var w _DecodedRecipients + var m schema.Maybe + *nb = _DecodedRecipients__Builder{_DecodedRecipients__Assembler{w: &w, m: &m}} +} + +type _DecodedRecipients__Assembler struct { + w *_DecodedRecipients + m *schema.Maybe + state laState + + cm schema.Maybe + va _DecodedRecipient__Assembler +} + +func (na *_DecodedRecipients__Assembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_DecodedRecipients__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients"}.BeginMap(0) +} +func (na *_DecodedRecipients__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if sizeHint < 0 { + sizeHint = 0 + } + if sizeHint > 0 { + na.w.x = make([]_DecodedRecipient, 0, sizeHint) + } + return na, nil +} +func (na *_DecodedRecipients__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_DecodedRecipients__Assembler) AssignBool(bool) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients"}.AssignBool(false) +} +func (_DecodedRecipients__Assembler) AssignInt(int64) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients"}.AssignInt(0) +} +func (_DecodedRecipients__Assembler) AssignFloat(float64) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients"}.AssignFloat(0) +} +func (_DecodedRecipients__Assembler) AssignString(string) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients"}.AssignString("") +} +func (_DecodedRecipients__Assembler) AssignBytes([]byte) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients"}.AssignBytes(nil) +} +func (_DecodedRecipients__Assembler) AssignLink(datamodel.Link) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients"}.AssignLink(nil) +} +func (na *_DecodedRecipients__Assembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_DecodedRecipients); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != datamodel.Kind_List { + return datamodel.ErrWrongKind{TypeName: "dagjose.DecodedRecipients", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_DecodedRecipients__Assembler) Prototype() datamodel.NodePrototype { + return _DecodedRecipients__Prototype{} +} +func (la *_DecodedRecipients__Assembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } +} +func (la *_DecodedRecipients__Assembler) AssembleValue() datamodel.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + la.w.x = append(la.w.x, _DecodedRecipient{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va +} +func (la *_DecodedRecipients__Assembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_DecodedRecipients__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype { + return _DecodedRecipient__Prototype{} +} +func (DecodedRecipients) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n DecodedRecipients) Representation() datamodel.Node { + return (*_DecodedRecipients__Repr)(n) +} + +type _DecodedRecipients__Repr _DecodedRecipients + +var _ datamodel.Node = &_DecodedRecipients__Repr{} + +func (_DecodedRecipients__Repr) Kind() datamodel.Kind { + return datamodel.Kind_List +} +func (_DecodedRecipients__Repr) LookupByString(string) (datamodel.Node, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients.Repr"}.LookupByString("") +} +func (nr *_DecodedRecipients__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + v, err := (DecodedRecipients)(nr).LookupByNode(k) + if err != nil || v == datamodel.Null { + return v, err + } + return v.(DecodedRecipient).Representation(), nil +} +func (nr *_DecodedRecipients__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + v, err := (DecodedRecipients)(nr).LookupByIndex(idx) + if err != nil || v == datamodel.Null { + return v, err + } + return v.(DecodedRecipient).Representation(), nil +} +func (n _DecodedRecipients__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.DecodedRecipients.Repr", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (_DecodedRecipients__Repr) MapIterator() datamodel.MapIterator { + return nil +} +func (nr *_DecodedRecipients__Repr) ListIterator() datamodel.ListIterator { + return &_DecodedRecipients__ReprListItr{(DecodedRecipients)(nr), 0} +} + +type _DecodedRecipients__ReprListItr _DecodedRecipients__ListItr + +func (itr *_DecodedRecipients__ReprListItr) Next() (idx int64, v datamodel.Node, err error) { + idx, v, err = (*_DecodedRecipients__ListItr)(itr).Next() + if err != nil || v == datamodel.Null { + return + } + return idx, v.(DecodedRecipient).Representation(), nil +} +func (itr *_DecodedRecipients__ReprListItr) Done() bool { + return (*_DecodedRecipients__ListItr)(itr).Done() +} + +func (rn *_DecodedRecipients__Repr) Length() int64 { + return int64(len(rn.x)) +} +func (_DecodedRecipients__Repr) IsAbsent() bool { + return false +} +func (_DecodedRecipients__Repr) IsNull() bool { + return false +} +func (_DecodedRecipients__Repr) AsBool() (bool, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients.Repr"}.AsBool() +} +func (_DecodedRecipients__Repr) AsInt() (int64, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients.Repr"}.AsInt() +} +func (_DecodedRecipients__Repr) AsFloat() (float64, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients.Repr"}.AsFloat() +} +func (_DecodedRecipients__Repr) AsString() (string, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients.Repr"}.AsString() +} +func (_DecodedRecipients__Repr) AsBytes() ([]byte, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients.Repr"}.AsBytes() +} +func (_DecodedRecipients__Repr) AsLink() (datamodel.Link, error) { + return mixins.List{TypeName: "dagjose.DecodedRecipients.Repr"}.AsLink() +} +func (_DecodedRecipients__Repr) Prototype() datamodel.NodePrototype { + return _DecodedRecipients__ReprPrototype{} +} + +type _DecodedRecipients__ReprPrototype struct{} + +func (_DecodedRecipients__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _DecodedRecipients__ReprBuilder + nb.Reset() + return &nb +} + +type _DecodedRecipients__ReprBuilder struct { + _DecodedRecipients__ReprAssembler +} + +func (nb *_DecodedRecipients__ReprBuilder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_DecodedRecipients__ReprBuilder) Reset() { + var w _DecodedRecipients + var m schema.Maybe + *nb = _DecodedRecipients__ReprBuilder{_DecodedRecipients__ReprAssembler{w: &w, m: &m}} +} + +type _DecodedRecipients__ReprAssembler struct { + w *_DecodedRecipients + m *schema.Maybe + state laState + + cm schema.Maybe + va _DecodedRecipient__ReprAssembler +} + +func (na *_DecodedRecipients__ReprAssembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_DecodedRecipients__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients.Repr"}.BeginMap(0) +} +func (na *_DecodedRecipients__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if sizeHint < 0 { + sizeHint = 0 + } + if sizeHint > 0 { + na.w.x = make([]_DecodedRecipient, 0, sizeHint) + } + return na, nil +} +func (na *_DecodedRecipients__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_DecodedRecipients__ReprAssembler) AssignBool(bool) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients.Repr"}.AssignBool(false) +} +func (_DecodedRecipients__ReprAssembler) AssignInt(int64) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients.Repr"}.AssignInt(0) +} +func (_DecodedRecipients__ReprAssembler) AssignFloat(float64) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients.Repr"}.AssignFloat(0) +} +func (_DecodedRecipients__ReprAssembler) AssignString(string) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients.Repr"}.AssignString("") +} +func (_DecodedRecipients__ReprAssembler) AssignBytes([]byte) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients.Repr"}.AssignBytes(nil) +} +func (_DecodedRecipients__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedRecipients.Repr"}.AssignLink(nil) +} +func (na *_DecodedRecipients__ReprAssembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_DecodedRecipients); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != datamodel.Kind_List { + return datamodel.ErrWrongKind{TypeName: "dagjose.DecodedRecipients.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_DecodedRecipients__ReprAssembler) Prototype() datamodel.NodePrototype { + return _DecodedRecipients__ReprPrototype{} +} +func (la *_DecodedRecipients__ReprAssembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } +} +func (la *_DecodedRecipients__ReprAssembler) AssembleValue() datamodel.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + la.w.x = append(la.w.x, _DecodedRecipient{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va +} +func (la *_DecodedRecipients__ReprAssembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_DecodedRecipients__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype { + return _DecodedRecipient__ReprPrototype{} +} + +func (n _DecodedSignature) FieldHeader() MaybeAny { + return &n.header +} +func (n _DecodedSignature) FieldProtected() MaybeBase64Url { + return &n.protected +} +func (n _DecodedSignature) FieldSignature() Base64Url { + return &n.signature +} + +type _DecodedSignature__Maybe struct { + m schema.Maybe + v DecodedSignature +} +type MaybeDecodedSignature = *_DecodedSignature__Maybe + +func (m MaybeDecodedSignature) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeDecodedSignature) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeDecodedSignature) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeDecodedSignature) AsNode() datamodel.Node { + switch m.m { + case schema.Maybe_Absent: + return datamodel.Absent + case schema.Maybe_Null: + return datamodel.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeDecodedSignature) Must() DecodedSignature { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var ( + fieldName__DecodedSignature_Header = _String{"header"} + fieldName__DecodedSignature_Protected = _String{"protected"} + fieldName__DecodedSignature_Signature = _String{"signature"} +) +var _ datamodel.Node = (DecodedSignature)(&_DecodedSignature{}) +var _ schema.TypedNode = (DecodedSignature)(&_DecodedSignature{}) + +func (DecodedSignature) Kind() datamodel.Kind { + return datamodel.Kind_Map +} +func (n DecodedSignature) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "header": + if n.header.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return n.header.v, nil + case "protected": + if n.protected.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.protected.v, nil + case "signature": + return &n.signature, nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} + } +} +func (n DecodedSignature) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (DecodedSignature) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature"}.LookupByIndex(0) +} +func (n DecodedSignature) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) +} +func (n DecodedSignature) MapIterator() datamodel.MapIterator { + return &_DecodedSignature__MapItr{n, 0} +} + +type _DecodedSignature__MapItr struct { + n DecodedSignature + idx int +} + +func (itr *_DecodedSignature__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { + if itr.idx >= 3 { + return nil, nil, datamodel.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__DecodedSignature_Header + if itr.n.header.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = itr.n.header.v + case 1: + k = &fieldName__DecodedSignature_Protected + if itr.n.protected.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.protected.v + case 2: + k = &fieldName__DecodedSignature_Signature + v = &itr.n.signature + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_DecodedSignature__MapItr) Done() bool { + return itr.idx >= 3 +} + +func (DecodedSignature) ListIterator() datamodel.ListIterator { + return nil +} +func (DecodedSignature) Length() int64 { + return 3 +} +func (DecodedSignature) IsAbsent() bool { + return false +} +func (DecodedSignature) IsNull() bool { + return false +} +func (DecodedSignature) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature"}.AsBool() +} +func (DecodedSignature) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature"}.AsInt() +} +func (DecodedSignature) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature"}.AsFloat() +} +func (DecodedSignature) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature"}.AsString() +} +func (DecodedSignature) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature"}.AsBytes() +} +func (DecodedSignature) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature"}.AsLink() +} +func (DecodedSignature) Prototype() datamodel.NodePrototype { + return _DecodedSignature__Prototype{} +} + +type _DecodedSignature__Prototype struct{} + +func (_DecodedSignature__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _DecodedSignature__Builder + nb.Reset() + return &nb +} + +type _DecodedSignature__Builder struct { + _DecodedSignature__Assembler +} + +func (nb *_DecodedSignature__Builder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_DecodedSignature__Builder) Reset() { + var w _DecodedSignature + var m schema.Maybe + *nb = _DecodedSignature__Builder{_DecodedSignature__Assembler{w: &w, m: &m}} +} + +type _DecodedSignature__Assembler struct { + w *_DecodedSignature + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_header _Any__Assembler + ca_protected _Base64Url__Assembler + ca_signature _Base64Url__Assembler +} + +func (na *_DecodedSignature__Assembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_header.reset() + na.ca_protected.reset() + na.ca_signature.reset() +} + +var ( + fieldBit__DecodedSignature_Header = 1 << 0 + fieldBit__DecodedSignature_Protected = 1 << 1 + fieldBit__DecodedSignature_Signature = 1 << 2 + fieldBits__DecodedSignature_sufficient = 0 + 1<<2 +) + +func (na *_DecodedSignature__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_DecodedSignature{} + } + return na, nil +} +func (_DecodedSignature__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature"}.BeginList(0) +} +func (na *_DecodedSignature__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_DecodedSignature__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature"}.AssignBool(false) +} +func (_DecodedSignature__Assembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature"}.AssignInt(0) +} +func (_DecodedSignature__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature"}.AssignFloat(0) +} +func (_DecodedSignature__Assembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature"}.AssignString("") +} +func (_DecodedSignature__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature"}.AssignBytes(nil) +} +func (_DecodedSignature__Assembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature"}.AssignLink(nil) +} +func (na *_DecodedSignature__Assembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_DecodedSignature); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != datamodel.Kind_Map { + return datamodel.ErrWrongKind{TypeName: "dagjose.DecodedSignature", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_DecodedSignature__Assembler) Prototype() datamodel.NodePrototype { + return _DecodedSignature__Prototype{} +} +func (ma *_DecodedSignature__Assembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.header.m { + case schema.Maybe_Value: + ma.w.header.v = ma.ca_header.w + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.protected.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 2: + switch ma.cm { + case schema.Maybe_Value: + ma.ca_signature.w = nil + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_DecodedSignature__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "header": + if ma.s&fieldBit__DecodedSignature_Header != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Header} + } + ma.s += fieldBit__DecodedSignature_Header + ma.state = maState_midValue + ma.f = 0 + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + return &ma.ca_header, nil + case "protected": + if ma.s&fieldBit__DecodedSignature_Protected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Protected} + } + ma.s += fieldBit__DecodedSignature_Protected + ma.state = maState_midValue + ma.f = 1 + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + return &ma.ca_protected, nil + case "signature": + if ma.s&fieldBit__DecodedSignature_Signature != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Signature} + } + ma.s += fieldBit__DecodedSignature_Signature + ma.state = maState_midValue + ma.f = 2 + ma.ca_signature.w = &ma.w.signature + ma.ca_signature.m = &ma.cm + return &ma.ca_signature, nil + } + return nil, schema.ErrInvalidKey{TypeName: "dagjose.DecodedSignature", Key: &_String{k}} +} +func (ma *_DecodedSignature__Assembler) AssembleKey() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_DecodedSignature__KeyAssembler)(ma) +} +func (ma *_DecodedSignature__Assembler) AssembleValue() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + return &ma.ca_header + case 1: + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + return &ma.ca_protected + case 2: + ma.ca_signature.w = &ma.w.signature + ma.ca_signature.m = &ma.cm + return &ma.ca_signature + default: + panic("unreachable") + } +} +func (ma *_DecodedSignature__Assembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__DecodedSignature_sufficient != fieldBits__DecodedSignature_sufficient { + err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} + if ma.s&fieldBit__DecodedSignature_Signature == 0 { + err.Missing = append(err.Missing, "signature") + } + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_DecodedSignature__Assembler) KeyPrototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (ma *_DecodedSignature__Assembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler valueprototype") +} + +type _DecodedSignature__KeyAssembler _DecodedSignature__Assembler + +func (_DecodedSignature__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.KeyAssembler"}.BeginMap(0) +} +func (_DecodedSignature__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.KeyAssembler"}.BeginList(0) +} +func (na *_DecodedSignature__KeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.KeyAssembler"}.AssignNull() +} +func (_DecodedSignature__KeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.KeyAssembler"}.AssignBool(false) +} +func (_DecodedSignature__KeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.KeyAssembler"}.AssignInt(0) +} +func (_DecodedSignature__KeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.KeyAssembler"}.AssignFloat(0) +} +func (ka *_DecodedSignature__KeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "header": + if ka.s&fieldBit__DecodedSignature_Header != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Header} + } + ka.s += fieldBit__DecodedSignature_Header + ka.state = maState_expectValue + ka.f = 0 + return nil + case "protected": + if ka.s&fieldBit__DecodedSignature_Protected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Protected} + } + ka.s += fieldBit__DecodedSignature_Protected + ka.state = maState_expectValue + ka.f = 1 + return nil + case "signature": + if ka.s&fieldBit__DecodedSignature_Signature != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Signature} + } + ka.s += fieldBit__DecodedSignature_Signature + ka.state = maState_expectValue + ka.f = 2 + return nil + default: + return schema.ErrInvalidKey{TypeName: "dagjose.DecodedSignature", Key: &_String{k}} + } +} +func (_DecodedSignature__KeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.KeyAssembler"}.AssignBytes(nil) +} +func (_DecodedSignature__KeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.KeyAssembler"}.AssignLink(nil) +} +func (ka *_DecodedSignature__KeyAssembler) AssignNode(v datamodel.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_DecodedSignature__KeyAssembler) Prototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (DecodedSignature) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n DecodedSignature) Representation() datamodel.Node { + return (*_DecodedSignature__Repr)(n) +} + +type _DecodedSignature__Repr _DecodedSignature + +var ( + fieldName__DecodedSignature_Header_serial = _String{"header"} + fieldName__DecodedSignature_Protected_serial = _String{"protected"} + fieldName__DecodedSignature_Signature_serial = _String{"signature"} +) +var _ datamodel.Node = &_DecodedSignature__Repr{} + +func (_DecodedSignature__Repr) Kind() datamodel.Kind { + return datamodel.Kind_Map +} +func (n *_DecodedSignature__Repr) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "header": + if n.header.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.header.v.Representation(), nil + case "protected": + if n.protected.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.protected.v.Representation(), nil + case "signature": + return n.signature.Representation(), nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} + } +} +func (n *_DecodedSignature__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (_DecodedSignature__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature.Repr"}.LookupByIndex(0) +} +func (n _DecodedSignature__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) +} +func (n *_DecodedSignature__Repr) MapIterator() datamodel.MapIterator { + return &_DecodedSignature__ReprMapItr{n, 0} +} + +type _DecodedSignature__ReprMapItr struct { + n *_DecodedSignature__Repr + idx int +} + +func (itr *_DecodedSignature__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { +advance: + if itr.idx >= 3 { + return nil, nil, datamodel.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__DecodedSignature_Header_serial + if itr.n.header.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.header.v.Representation() + case 1: + k = &fieldName__DecodedSignature_Protected_serial + if itr.n.protected.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.protected.v.Representation() + case 2: + k = &fieldName__DecodedSignature_Signature_serial + v = itr.n.signature.Representation() + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_DecodedSignature__ReprMapItr) Done() bool { + return itr.idx >= 3 +} +func (_DecodedSignature__Repr) ListIterator() datamodel.ListIterator { + return nil +} +func (rn *_DecodedSignature__Repr) Length() int64 { + l := 3 + if rn.header.m == schema.Maybe_Absent { + l-- + } + if rn.protected.m == schema.Maybe_Absent { + l-- + } + return int64(l) +} +func (_DecodedSignature__Repr) IsAbsent() bool { + return false +} +func (_DecodedSignature__Repr) IsNull() bool { + return false +} +func (_DecodedSignature__Repr) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature.Repr"}.AsBool() +} +func (_DecodedSignature__Repr) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature.Repr"}.AsInt() +} +func (_DecodedSignature__Repr) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature.Repr"}.AsFloat() +} +func (_DecodedSignature__Repr) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature.Repr"}.AsString() +} +func (_DecodedSignature__Repr) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature.Repr"}.AsBytes() +} +func (_DecodedSignature__Repr) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.DecodedSignature.Repr"}.AsLink() +} +func (_DecodedSignature__Repr) Prototype() datamodel.NodePrototype { + return _DecodedSignature__ReprPrototype{} +} + +type _DecodedSignature__ReprPrototype struct{} + +func (_DecodedSignature__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _DecodedSignature__ReprBuilder + nb.Reset() + return &nb +} + +type _DecodedSignature__ReprBuilder struct { + _DecodedSignature__ReprAssembler +} + +func (nb *_DecodedSignature__ReprBuilder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_DecodedSignature__ReprBuilder) Reset() { + var w _DecodedSignature + var m schema.Maybe + *nb = _DecodedSignature__ReprBuilder{_DecodedSignature__ReprAssembler{w: &w, m: &m}} +} + +type _DecodedSignature__ReprAssembler struct { + w *_DecodedSignature + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_header _Any__ReprAssembler + ca_protected _Base64Url__ReprAssembler + ca_signature _Base64Url__ReprAssembler +} + +func (na *_DecodedSignature__ReprAssembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_header.reset() + na.ca_protected.reset() + na.ca_signature.reset() +} +func (na *_DecodedSignature__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_DecodedSignature{} + } + return na, nil +} +func (_DecodedSignature__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature.Repr"}.BeginList(0) +} +func (na *_DecodedSignature__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_DecodedSignature__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature.Repr"}.AssignBool(false) +} +func (_DecodedSignature__ReprAssembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature.Repr"}.AssignInt(0) +} +func (_DecodedSignature__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature.Repr"}.AssignFloat(0) +} +func (_DecodedSignature__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature.Repr"}.AssignString("") +} +func (_DecodedSignature__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature.Repr"}.AssignBytes(nil) +} +func (_DecodedSignature__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.DecodedSignature.Repr"}.AssignLink(nil) +} +func (na *_DecodedSignature__ReprAssembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_DecodedSignature); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != datamodel.Kind_Map { + return datamodel.ErrWrongKind{TypeName: "dagjose.DecodedSignature.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_DecodedSignature__ReprAssembler) Prototype() datamodel.NodePrototype { + return _DecodedSignature__ReprPrototype{} +} +func (ma *_DecodedSignature__ReprAssembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.header.m { + case schema.Maybe_Value: + ma.w.header.v = ma.ca_header.w + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.protected.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 2: + switch ma.cm { + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_DecodedSignature__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "header": + if ma.s&fieldBit__DecodedSignature_Header != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Header_serial} + } + ma.s += fieldBit__DecodedSignature_Header + ma.state = maState_midValue + ma.f = 0 + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + + return &ma.ca_header, nil + case "protected": + if ma.s&fieldBit__DecodedSignature_Protected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Protected_serial} + } + ma.s += fieldBit__DecodedSignature_Protected + ma.state = maState_midValue + ma.f = 1 + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + + return &ma.ca_protected, nil + case "signature": + if ma.s&fieldBit__DecodedSignature_Signature != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Signature_serial} + } + ma.s += fieldBit__DecodedSignature_Signature + ma.state = maState_midValue + ma.f = 2 + ma.ca_signature.w = &ma.w.signature + ma.ca_signature.m = &ma.cm + return &ma.ca_signature, nil + default: + } + return nil, schema.ErrInvalidKey{TypeName: "dagjose.DecodedSignature.Repr", Key: &_String{k}} +} +func (ma *_DecodedSignature__ReprAssembler) AssembleKey() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_DecodedSignature__ReprKeyAssembler)(ma) +} +func (ma *_DecodedSignature__ReprAssembler) AssembleValue() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + + return &ma.ca_header + case 1: + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + + return &ma.ca_protected + case 2: + ma.ca_signature.w = &ma.w.signature + ma.ca_signature.m = &ma.cm + return &ma.ca_signature + default: + panic("unreachable") + } +} +func (ma *_DecodedSignature__ReprAssembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__DecodedSignature_sufficient != fieldBits__DecodedSignature_sufficient { + err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} + if ma.s&fieldBit__DecodedSignature_Signature == 0 { + err.Missing = append(err.Missing, "signature") + } + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_DecodedSignature__ReprAssembler) KeyPrototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (ma *_DecodedSignature__ReprAssembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler repr valueprototype") +} + +type _DecodedSignature__ReprKeyAssembler _DecodedSignature__ReprAssembler + +func (_DecodedSignature__ReprKeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.Repr.KeyAssembler"}.BeginMap(0) +} +func (_DecodedSignature__ReprKeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.Repr.KeyAssembler"}.BeginList(0) +} +func (na *_DecodedSignature__ReprKeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.Repr.KeyAssembler"}.AssignNull() +} +func (_DecodedSignature__ReprKeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.Repr.KeyAssembler"}.AssignBool(false) +} +func (_DecodedSignature__ReprKeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.Repr.KeyAssembler"}.AssignInt(0) +} +func (_DecodedSignature__ReprKeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.Repr.KeyAssembler"}.AssignFloat(0) +} +func (ka *_DecodedSignature__ReprKeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "header": + if ka.s&fieldBit__DecodedSignature_Header != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Header_serial} + } + ka.s += fieldBit__DecodedSignature_Header + ka.state = maState_expectValue + ka.f = 0 + return nil + case "protected": + if ka.s&fieldBit__DecodedSignature_Protected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Protected_serial} + } + ka.s += fieldBit__DecodedSignature_Protected + ka.state = maState_expectValue + ka.f = 1 + return nil + case "signature": + if ka.s&fieldBit__DecodedSignature_Signature != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__DecodedSignature_Signature_serial} + } + ka.s += fieldBit__DecodedSignature_Signature + ka.state = maState_expectValue + ka.f = 2 + return nil + } + return schema.ErrInvalidKey{TypeName: "dagjose.DecodedSignature.Repr", Key: &_String{k}} +} +func (_DecodedSignature__ReprKeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.Repr.KeyAssembler"}.AssignBytes(nil) +} +func (_DecodedSignature__ReprKeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.DecodedSignature.Repr.KeyAssembler"}.AssignLink(nil) +} +func (ka *_DecodedSignature__ReprKeyAssembler) AssignNode(v datamodel.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_DecodedSignature__ReprKeyAssembler) Prototype() datamodel.NodePrototype { + return _String__Prototype{} +} + +func (n *_DecodedSignatures) Lookup(idx int64) DecodedSignature { + if n.Length() <= idx { + return nil + } + v := &n.x[idx] + return v +} +func (n *_DecodedSignatures) LookupMaybe(idx int64) MaybeDecodedSignature { + if n.Length() <= idx { + return nil + } + v := &n.x[idx] + return &_DecodedSignature__Maybe{ + m: schema.Maybe_Value, + v: v, + } +} + +var _DecodedSignatures__valueAbsent = _DecodedSignature__Maybe{m: schema.Maybe_Absent} + +func (n DecodedSignatures) Iterator() *DecodedSignatures__Itr { + return &DecodedSignatures__Itr{n, 0} +} + +type DecodedSignatures__Itr struct { + n DecodedSignatures + idx int +} + +func (itr *DecodedSignatures__Itr) Next() (idx int64, v DecodedSignature) { + if itr.idx >= len(itr.n.x) { + return -1, nil + } + idx = int64(itr.idx) + v = &itr.n.x[itr.idx] + itr.idx++ + return +} +func (itr *DecodedSignatures__Itr) Done() bool { + return itr.idx >= len(itr.n.x) +} + +type _DecodedSignatures__Maybe struct { + m schema.Maybe + v _DecodedSignatures +} +type MaybeDecodedSignatures = *_DecodedSignatures__Maybe + +func (m MaybeDecodedSignatures) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeDecodedSignatures) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeDecodedSignatures) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeDecodedSignatures) AsNode() datamodel.Node { + switch m.m { + case schema.Maybe_Absent: + return datamodel.Absent + case schema.Maybe_Null: + return datamodel.Null + case schema.Maybe_Value: + return &m.v + default: + panic("unreachable") + } +} +func (m MaybeDecodedSignatures) Must() DecodedSignatures { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return &m.v +} + +var _ datamodel.Node = (DecodedSignatures)(&_DecodedSignatures{}) +var _ schema.TypedNode = (DecodedSignatures)(&_DecodedSignatures{}) + +func (DecodedSignatures) Kind() datamodel.Kind { + return datamodel.Kind_List +} +func (DecodedSignatures) LookupByString(string) (datamodel.Node, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures"}.LookupByString("") +} +func (n DecodedSignatures) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + idx, err := k.AsInt() + if err != nil { + return nil, err + } + return n.LookupByIndex(idx) +} +func (n DecodedSignatures) LookupByIndex(idx int64) (datamodel.Node, error) { + if n.Length() <= idx { + return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)} + } + v := &n.x[idx] + return v, nil +} +func (n DecodedSignatures) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.DecodedSignatures", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (DecodedSignatures) MapIterator() datamodel.MapIterator { + return nil +} +func (n DecodedSignatures) ListIterator() datamodel.ListIterator { + return &_DecodedSignatures__ListItr{n, 0} +} + +type _DecodedSignatures__ListItr struct { + n DecodedSignatures + idx int +} + +func (itr *_DecodedSignatures__ListItr) Next() (idx int64, v datamodel.Node, _ error) { + if itr.idx >= len(itr.n.x) { + return -1, nil, datamodel.ErrIteratorOverread{} + } + idx = int64(itr.idx) + x := &itr.n.x[itr.idx] + v = x + itr.idx++ + return +} +func (itr *_DecodedSignatures__ListItr) Done() bool { + return itr.idx >= len(itr.n.x) +} + +func (n DecodedSignatures) Length() int64 { + return int64(len(n.x)) +} +func (DecodedSignatures) IsAbsent() bool { + return false +} +func (DecodedSignatures) IsNull() bool { + return false +} +func (DecodedSignatures) AsBool() (bool, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures"}.AsBool() +} +func (DecodedSignatures) AsInt() (int64, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures"}.AsInt() +} +func (DecodedSignatures) AsFloat() (float64, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures"}.AsFloat() +} +func (DecodedSignatures) AsString() (string, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures"}.AsString() +} +func (DecodedSignatures) AsBytes() ([]byte, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures"}.AsBytes() +} +func (DecodedSignatures) AsLink() (datamodel.Link, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures"}.AsLink() +} +func (DecodedSignatures) Prototype() datamodel.NodePrototype { + return _DecodedSignatures__Prototype{} +} + +type _DecodedSignatures__Prototype struct{} + +func (_DecodedSignatures__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _DecodedSignatures__Builder + nb.Reset() + return &nb +} + +type _DecodedSignatures__Builder struct { + _DecodedSignatures__Assembler +} + +func (nb *_DecodedSignatures__Builder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_DecodedSignatures__Builder) Reset() { + var w _DecodedSignatures + var m schema.Maybe + *nb = _DecodedSignatures__Builder{_DecodedSignatures__Assembler{w: &w, m: &m}} +} + +type _DecodedSignatures__Assembler struct { + w *_DecodedSignatures + m *schema.Maybe + state laState + + cm schema.Maybe + va _DecodedSignature__Assembler +} + +func (na *_DecodedSignatures__Assembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_DecodedSignatures__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures"}.BeginMap(0) +} +func (na *_DecodedSignatures__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if sizeHint < 0 { + sizeHint = 0 + } + if sizeHint > 0 { + na.w.x = make([]_DecodedSignature, 0, sizeHint) + } + return na, nil +} +func (na *_DecodedSignatures__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_DecodedSignatures__Assembler) AssignBool(bool) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures"}.AssignBool(false) +} +func (_DecodedSignatures__Assembler) AssignInt(int64) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures"}.AssignInt(0) +} +func (_DecodedSignatures__Assembler) AssignFloat(float64) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures"}.AssignFloat(0) +} +func (_DecodedSignatures__Assembler) AssignString(string) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures"}.AssignString("") +} +func (_DecodedSignatures__Assembler) AssignBytes([]byte) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures"}.AssignBytes(nil) +} +func (_DecodedSignatures__Assembler) AssignLink(datamodel.Link) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures"}.AssignLink(nil) +} +func (na *_DecodedSignatures__Assembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_DecodedSignatures); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != datamodel.Kind_List { + return datamodel.ErrWrongKind{TypeName: "dagjose.DecodedSignatures", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_DecodedSignatures__Assembler) Prototype() datamodel.NodePrototype { + return _DecodedSignatures__Prototype{} +} +func (la *_DecodedSignatures__Assembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } +} +func (la *_DecodedSignatures__Assembler) AssembleValue() datamodel.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + la.w.x = append(la.w.x, _DecodedSignature{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va +} +func (la *_DecodedSignatures__Assembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_DecodedSignatures__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype { + return _DecodedSignature__Prototype{} +} +func (DecodedSignatures) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n DecodedSignatures) Representation() datamodel.Node { + return (*_DecodedSignatures__Repr)(n) +} + +type _DecodedSignatures__Repr _DecodedSignatures + +var _ datamodel.Node = &_DecodedSignatures__Repr{} + +func (_DecodedSignatures__Repr) Kind() datamodel.Kind { + return datamodel.Kind_List +} +func (_DecodedSignatures__Repr) LookupByString(string) (datamodel.Node, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures.Repr"}.LookupByString("") +} +func (nr *_DecodedSignatures__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + v, err := (DecodedSignatures)(nr).LookupByNode(k) + if err != nil || v == datamodel.Null { + return v, err + } + return v.(DecodedSignature).Representation(), nil +} +func (nr *_DecodedSignatures__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + v, err := (DecodedSignatures)(nr).LookupByIndex(idx) + if err != nil || v == datamodel.Null { + return v, err + } + return v.(DecodedSignature).Representation(), nil +} +func (n _DecodedSignatures__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.DecodedSignatures.Repr", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (_DecodedSignatures__Repr) MapIterator() datamodel.MapIterator { + return nil +} +func (nr *_DecodedSignatures__Repr) ListIterator() datamodel.ListIterator { + return &_DecodedSignatures__ReprListItr{(DecodedSignatures)(nr), 0} +} + +type _DecodedSignatures__ReprListItr _DecodedSignatures__ListItr + +func (itr *_DecodedSignatures__ReprListItr) Next() (idx int64, v datamodel.Node, err error) { + idx, v, err = (*_DecodedSignatures__ListItr)(itr).Next() + if err != nil || v == datamodel.Null { + return + } + return idx, v.(DecodedSignature).Representation(), nil +} +func (itr *_DecodedSignatures__ReprListItr) Done() bool { + return (*_DecodedSignatures__ListItr)(itr).Done() +} + +func (rn *_DecodedSignatures__Repr) Length() int64 { + return int64(len(rn.x)) +} +func (_DecodedSignatures__Repr) IsAbsent() bool { + return false +} +func (_DecodedSignatures__Repr) IsNull() bool { + return false +} +func (_DecodedSignatures__Repr) AsBool() (bool, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures.Repr"}.AsBool() +} +func (_DecodedSignatures__Repr) AsInt() (int64, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures.Repr"}.AsInt() +} +func (_DecodedSignatures__Repr) AsFloat() (float64, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures.Repr"}.AsFloat() +} +func (_DecodedSignatures__Repr) AsString() (string, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures.Repr"}.AsString() +} +func (_DecodedSignatures__Repr) AsBytes() ([]byte, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures.Repr"}.AsBytes() +} +func (_DecodedSignatures__Repr) AsLink() (datamodel.Link, error) { + return mixins.List{TypeName: "dagjose.DecodedSignatures.Repr"}.AsLink() +} +func (_DecodedSignatures__Repr) Prototype() datamodel.NodePrototype { + return _DecodedSignatures__ReprPrototype{} +} + +type _DecodedSignatures__ReprPrototype struct{} + +func (_DecodedSignatures__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _DecodedSignatures__ReprBuilder + nb.Reset() + return &nb +} + +type _DecodedSignatures__ReprBuilder struct { + _DecodedSignatures__ReprAssembler +} + +func (nb *_DecodedSignatures__ReprBuilder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_DecodedSignatures__ReprBuilder) Reset() { + var w _DecodedSignatures + var m schema.Maybe + *nb = _DecodedSignatures__ReprBuilder{_DecodedSignatures__ReprAssembler{w: &w, m: &m}} +} + +type _DecodedSignatures__ReprAssembler struct { + w *_DecodedSignatures + m *schema.Maybe + state laState + + cm schema.Maybe + va _DecodedSignature__ReprAssembler +} + +func (na *_DecodedSignatures__ReprAssembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_DecodedSignatures__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures.Repr"}.BeginMap(0) +} +func (na *_DecodedSignatures__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if sizeHint < 0 { + sizeHint = 0 + } + if sizeHint > 0 { + na.w.x = make([]_DecodedSignature, 0, sizeHint) + } + return na, nil +} +func (na *_DecodedSignatures__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_DecodedSignatures__ReprAssembler) AssignBool(bool) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures.Repr"}.AssignBool(false) +} +func (_DecodedSignatures__ReprAssembler) AssignInt(int64) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures.Repr"}.AssignInt(0) +} +func (_DecodedSignatures__ReprAssembler) AssignFloat(float64) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures.Repr"}.AssignFloat(0) +} +func (_DecodedSignatures__ReprAssembler) AssignString(string) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures.Repr"}.AssignString("") +} +func (_DecodedSignatures__ReprAssembler) AssignBytes([]byte) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures.Repr"}.AssignBytes(nil) +} +func (_DecodedSignatures__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.ListAssembler{TypeName: "dagjose.DecodedSignatures.Repr"}.AssignLink(nil) +} +func (na *_DecodedSignatures__ReprAssembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_DecodedSignatures); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != datamodel.Kind_List { + return datamodel.ErrWrongKind{TypeName: "dagjose.DecodedSignatures.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_DecodedSignatures__ReprAssembler) Prototype() datamodel.NodePrototype { + return _DecodedSignatures__ReprPrototype{} +} +func (la *_DecodedSignatures__ReprAssembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } +} +func (la *_DecodedSignatures__ReprAssembler) AssembleValue() datamodel.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + la.w.x = append(la.w.x, _DecodedSignature{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va +} +func (la *_DecodedSignatures__ReprAssembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_DecodedSignatures__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype { + return _DecodedSignature__ReprPrototype{} +} + +func (n _EncodedJOSE) FieldAad() MaybeRaw { + return &n.aad +} +func (n _EncodedJOSE) FieldCiphertext() MaybeRaw { + return &n.ciphertext +} +func (n _EncodedJOSE) FieldIv() MaybeRaw { + return &n.iv +} +func (n _EncodedJOSE) FieldLink() MaybeLink { + return &n.link +} +func (n _EncodedJOSE) FieldPayload() MaybeRaw { + return &n.payload +} +func (n _EncodedJOSE) FieldProtected() MaybeRaw { + return &n.protected +} +func (n _EncodedJOSE) FieldRecipients() MaybeEncodedRecipients { + return &n.recipients +} +func (n _EncodedJOSE) FieldSignatures() MaybeEncodedSignatures { + return &n.signatures +} +func (n _EncodedJOSE) FieldTag() MaybeRaw { + return &n.tag +} +func (n _EncodedJOSE) FieldUnprotected() MaybeAny { + return &n.unprotected +} + +type _EncodedJOSE__Maybe struct { + m schema.Maybe + v EncodedJOSE +} +type MaybeEncodedJOSE = *_EncodedJOSE__Maybe + +func (m MaybeEncodedJOSE) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeEncodedJOSE) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeEncodedJOSE) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeEncodedJOSE) AsNode() datamodel.Node { + switch m.m { + case schema.Maybe_Absent: + return datamodel.Absent + case schema.Maybe_Null: + return datamodel.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeEncodedJOSE) Must() EncodedJOSE { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var ( + fieldName__EncodedJOSE_Aad = _String{"aad"} + fieldName__EncodedJOSE_Ciphertext = _String{"ciphertext"} + fieldName__EncodedJOSE_Iv = _String{"iv"} + fieldName__EncodedJOSE_Link = _String{"link"} + fieldName__EncodedJOSE_Payload = _String{"payload"} + fieldName__EncodedJOSE_Protected = _String{"protected"} + fieldName__EncodedJOSE_Recipients = _String{"recipients"} + fieldName__EncodedJOSE_Signatures = _String{"signatures"} + fieldName__EncodedJOSE_Tag = _String{"tag"} + fieldName__EncodedJOSE_Unprotected = _String{"unprotected"} +) +var _ datamodel.Node = (EncodedJOSE)(&_EncodedJOSE{}) +var _ schema.TypedNode = (EncodedJOSE)(&_EncodedJOSE{}) + +func (EncodedJOSE) Kind() datamodel.Kind { + return datamodel.Kind_Map +} +func (n EncodedJOSE) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "aad": + if n.aad.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.aad.v, nil + case "ciphertext": + if n.ciphertext.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.ciphertext.v, nil + case "iv": + if n.iv.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.iv.v, nil + case "link": + if n.link.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.link.v, nil + case "payload": + if n.payload.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.payload.v, nil + case "protected": + if n.protected.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.protected.v, nil + case "recipients": + if n.recipients.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.recipients.v, nil + case "signatures": + if n.signatures.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.signatures.v, nil + case "tag": + if n.tag.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.tag.v, nil + case "unprotected": + if n.unprotected.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return n.unprotected.v, nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} + } +} +func (n EncodedJOSE) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (EncodedJOSE) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE"}.LookupByIndex(0) +} +func (n EncodedJOSE) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) +} +func (n EncodedJOSE) MapIterator() datamodel.MapIterator { + return &_EncodedJOSE__MapItr{n, 0} +} + +type _EncodedJOSE__MapItr struct { + n EncodedJOSE + idx int +} + +func (itr *_EncodedJOSE__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { + if itr.idx >= 10 { + return nil, nil, datamodel.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__EncodedJOSE_Aad + if itr.n.aad.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.aad.v + case 1: + k = &fieldName__EncodedJOSE_Ciphertext + if itr.n.ciphertext.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.ciphertext.v + case 2: + k = &fieldName__EncodedJOSE_Iv + if itr.n.iv.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.iv.v + case 3: + k = &fieldName__EncodedJOSE_Link + if itr.n.link.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.link.v + case 4: + k = &fieldName__EncodedJOSE_Payload + if itr.n.payload.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.payload.v + case 5: + k = &fieldName__EncodedJOSE_Protected + if itr.n.protected.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.protected.v + case 6: + k = &fieldName__EncodedJOSE_Recipients + if itr.n.recipients.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.recipients.v + case 7: + k = &fieldName__EncodedJOSE_Signatures + if itr.n.signatures.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.signatures.v + case 8: + k = &fieldName__EncodedJOSE_Tag + if itr.n.tag.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.tag.v + case 9: + k = &fieldName__EncodedJOSE_Unprotected + if itr.n.unprotected.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = itr.n.unprotected.v + default: + panic("unreachable") + } + itr.idx++ + return } -func (Int) AsString() (string, error) { - return mixins.Int{TypeName: "dagjose.Int"}.AsString() +func (itr *_EncodedJOSE__MapItr) Done() bool { + return itr.idx >= 10 } -func (Int) AsBytes() ([]byte, error) { - return mixins.Int{TypeName: "dagjose.Int"}.AsBytes() + +func (EncodedJOSE) ListIterator() datamodel.ListIterator { + return nil } -func (Int) AsLink() (datamodel.Link, error) { - return mixins.Int{TypeName: "dagjose.Int"}.AsLink() +func (EncodedJOSE) Length() int64 { + return 10 } -func (Int) Prototype() datamodel.NodePrototype { - return _Int__Prototype{} +func (EncodedJOSE) IsAbsent() bool { + return false +} +func (EncodedJOSE) IsNull() bool { + return false +} +func (EncodedJOSE) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE"}.AsBool() +} +func (EncodedJOSE) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE"}.AsInt() +} +func (EncodedJOSE) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE"}.AsFloat() +} +func (EncodedJOSE) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE"}.AsString() +} +func (EncodedJOSE) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE"}.AsBytes() +} +func (EncodedJOSE) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE"}.AsLink() +} +func (EncodedJOSE) Prototype() datamodel.NodePrototype { + return _EncodedJOSE__Prototype{} +} + +type _EncodedJOSE__Prototype struct{} + +func (_EncodedJOSE__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _EncodedJOSE__Builder + nb.Reset() + return &nb +} + +type _EncodedJOSE__Builder struct { + _EncodedJOSE__Assembler +} + +func (nb *_EncodedJOSE__Builder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_EncodedJOSE__Builder) Reset() { + var w _EncodedJOSE + var m schema.Maybe + *nb = _EncodedJOSE__Builder{_EncodedJOSE__Assembler{w: &w, m: &m}} +} + +type _EncodedJOSE__Assembler struct { + w *_EncodedJOSE + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_aad _Raw__Assembler + ca_ciphertext _Raw__Assembler + ca_iv _Raw__Assembler + ca_link _Link__Assembler + ca_payload _Raw__Assembler + ca_protected _Raw__Assembler + ca_recipients _EncodedRecipients__Assembler + ca_signatures _EncodedSignatures__Assembler + ca_tag _Raw__Assembler + ca_unprotected _Any__Assembler +} + +func (na *_EncodedJOSE__Assembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_aad.reset() + na.ca_ciphertext.reset() + na.ca_iv.reset() + na.ca_link.reset() + na.ca_payload.reset() + na.ca_protected.reset() + na.ca_recipients.reset() + na.ca_signatures.reset() + na.ca_tag.reset() + na.ca_unprotected.reset() +} + +var ( + fieldBit__EncodedJOSE_Aad = 1 << 0 + fieldBit__EncodedJOSE_Ciphertext = 1 << 1 + fieldBit__EncodedJOSE_Iv = 1 << 2 + fieldBit__EncodedJOSE_Link = 1 << 3 + fieldBit__EncodedJOSE_Payload = 1 << 4 + fieldBit__EncodedJOSE_Protected = 1 << 5 + fieldBit__EncodedJOSE_Recipients = 1 << 6 + fieldBit__EncodedJOSE_Signatures = 1 << 7 + fieldBit__EncodedJOSE_Tag = 1 << 8 + fieldBit__EncodedJOSE_Unprotected = 1 << 9 + fieldBits__EncodedJOSE_sufficient = 0 +) + +func (na *_EncodedJOSE__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_EncodedJOSE{} + } + return na, nil +} +func (_EncodedJOSE__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE"}.BeginList(0) +} +func (na *_EncodedJOSE__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_EncodedJOSE__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE"}.AssignBool(false) +} +func (_EncodedJOSE__Assembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE"}.AssignInt(0) +} +func (_EncodedJOSE__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE"}.AssignFloat(0) +} +func (_EncodedJOSE__Assembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE"}.AssignString("") +} +func (_EncodedJOSE__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE"}.AssignBytes(nil) +} +func (_EncodedJOSE__Assembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE"}.AssignLink(nil) +} +func (na *_EncodedJOSE__Assembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_EncodedJOSE); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != datamodel.Kind_Map { + return datamodel.ErrWrongKind{TypeName: "dagjose.EncodedJOSE", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_EncodedJOSE__Assembler) Prototype() datamodel.NodePrototype { + return _EncodedJOSE__Prototype{} +} +func (ma *_EncodedJOSE__Assembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.aad.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.ciphertext.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 2: + switch ma.w.iv.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 3: + switch ma.w.link.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 4: + switch ma.w.payload.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 5: + switch ma.w.protected.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 6: + switch ma.w.recipients.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 7: + switch ma.w.signatures.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 8: + switch ma.w.tag.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 9: + switch ma.w.unprotected.m { + case schema.Maybe_Value: + ma.w.unprotected.v = ma.ca_unprotected.w + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_EncodedJOSE__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "aad": + if ma.s&fieldBit__EncodedJOSE_Aad != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Aad} + } + ma.s += fieldBit__EncodedJOSE_Aad + ma.state = maState_midValue + ma.f = 0 + ma.ca_aad.w = &ma.w.aad.v + ma.ca_aad.m = &ma.w.aad.m + return &ma.ca_aad, nil + case "ciphertext": + if ma.s&fieldBit__EncodedJOSE_Ciphertext != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Ciphertext} + } + ma.s += fieldBit__EncodedJOSE_Ciphertext + ma.state = maState_midValue + ma.f = 1 + ma.ca_ciphertext.w = &ma.w.ciphertext.v + ma.ca_ciphertext.m = &ma.w.ciphertext.m + return &ma.ca_ciphertext, nil + case "iv": + if ma.s&fieldBit__EncodedJOSE_Iv != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Iv} + } + ma.s += fieldBit__EncodedJOSE_Iv + ma.state = maState_midValue + ma.f = 2 + ma.ca_iv.w = &ma.w.iv.v + ma.ca_iv.m = &ma.w.iv.m + return &ma.ca_iv, nil + case "link": + if ma.s&fieldBit__EncodedJOSE_Link != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Link} + } + ma.s += fieldBit__EncodedJOSE_Link + ma.state = maState_midValue + ma.f = 3 + ma.ca_link.w = &ma.w.link.v + ma.ca_link.m = &ma.w.link.m + return &ma.ca_link, nil + case "payload": + if ma.s&fieldBit__EncodedJOSE_Payload != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Payload} + } + ma.s += fieldBit__EncodedJOSE_Payload + ma.state = maState_midValue + ma.f = 4 + ma.ca_payload.w = &ma.w.payload.v + ma.ca_payload.m = &ma.w.payload.m + return &ma.ca_payload, nil + case "protected": + if ma.s&fieldBit__EncodedJOSE_Protected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Protected} + } + ma.s += fieldBit__EncodedJOSE_Protected + ma.state = maState_midValue + ma.f = 5 + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + return &ma.ca_protected, nil + case "recipients": + if ma.s&fieldBit__EncodedJOSE_Recipients != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Recipients} + } + ma.s += fieldBit__EncodedJOSE_Recipients + ma.state = maState_midValue + ma.f = 6 + ma.ca_recipients.w = &ma.w.recipients.v + ma.ca_recipients.m = &ma.w.recipients.m + return &ma.ca_recipients, nil + case "signatures": + if ma.s&fieldBit__EncodedJOSE_Signatures != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Signatures} + } + ma.s += fieldBit__EncodedJOSE_Signatures + ma.state = maState_midValue + ma.f = 7 + ma.ca_signatures.w = &ma.w.signatures.v + ma.ca_signatures.m = &ma.w.signatures.m + return &ma.ca_signatures, nil + case "tag": + if ma.s&fieldBit__EncodedJOSE_Tag != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Tag} + } + ma.s += fieldBit__EncodedJOSE_Tag + ma.state = maState_midValue + ma.f = 8 + ma.ca_tag.w = &ma.w.tag.v + ma.ca_tag.m = &ma.w.tag.m + return &ma.ca_tag, nil + case "unprotected": + if ma.s&fieldBit__EncodedJOSE_Unprotected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Unprotected} + } + ma.s += fieldBit__EncodedJOSE_Unprotected + ma.state = maState_midValue + ma.f = 9 + ma.ca_unprotected.w = ma.w.unprotected.v + ma.ca_unprotected.m = &ma.w.unprotected.m + return &ma.ca_unprotected, nil + } + return nil, schema.ErrInvalidKey{TypeName: "dagjose.EncodedJOSE", Key: &_String{k}} } - -type _Int__Prototype struct{} - -func (_Int__Prototype) NewBuilder() datamodel.NodeBuilder { - var nb _Int__Builder - nb.Reset() - return &nb +func (ma *_EncodedJOSE__Assembler) AssembleKey() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_EncodedJOSE__KeyAssembler)(ma) } - -type _Int__Builder struct { - _Int__Assembler +func (ma *_EncodedJOSE__Assembler) AssembleValue() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_aad.w = &ma.w.aad.v + ma.ca_aad.m = &ma.w.aad.m + return &ma.ca_aad + case 1: + ma.ca_ciphertext.w = &ma.w.ciphertext.v + ma.ca_ciphertext.m = &ma.w.ciphertext.m + return &ma.ca_ciphertext + case 2: + ma.ca_iv.w = &ma.w.iv.v + ma.ca_iv.m = &ma.w.iv.m + return &ma.ca_iv + case 3: + ma.ca_link.w = &ma.w.link.v + ma.ca_link.m = &ma.w.link.m + return &ma.ca_link + case 4: + ma.ca_payload.w = &ma.w.payload.v + ma.ca_payload.m = &ma.w.payload.m + return &ma.ca_payload + case 5: + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + return &ma.ca_protected + case 6: + ma.ca_recipients.w = &ma.w.recipients.v + ma.ca_recipients.m = &ma.w.recipients.m + return &ma.ca_recipients + case 7: + ma.ca_signatures.w = &ma.w.signatures.v + ma.ca_signatures.m = &ma.w.signatures.m + return &ma.ca_signatures + case 8: + ma.ca_tag.w = &ma.w.tag.v + ma.ca_tag.m = &ma.w.tag.m + return &ma.ca_tag + case 9: + ma.ca_unprotected.w = ma.w.unprotected.v + ma.ca_unprotected.m = &ma.w.unprotected.m + return &ma.ca_unprotected + default: + panic("unreachable") + } } - -func (nb *_Int__Builder) Build() datamodel.Node { - if *nb.m != schema.Maybe_Value { - panic("invalid state: cannot call Build on an assembler that's not finished") +func (ma *_EncodedJOSE__Assembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") } - return nb.w + if ma.s&fieldBits__EncodedJOSE_sufficient != fieldBits__EncodedJOSE_sufficient { + err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil } -func (nb *_Int__Builder) Reset() { - var w _Int - var m schema.Maybe - *nb = _Int__Builder{_Int__Assembler{w: &w, m: &m}} +func (ma *_EncodedJOSE__Assembler) KeyPrototype() datamodel.NodePrototype { + return _String__Prototype{} } - -type _Int__Assembler struct { - w *_Int - m *schema.Maybe +func (ma *_EncodedJOSE__Assembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler valueprototype") } -func (na *_Int__Assembler) reset() {} -func (_Int__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.IntAssembler{TypeName: "dagjose.Int"}.BeginMap(0) -} -func (_Int__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.IntAssembler{TypeName: "dagjose.Int"}.BeginList(0) -} -func (na *_Int__Assembler) AssignNull() error { - switch *na.m { - case allowNull: - *na.m = schema.Maybe_Null - return nil - case schema.Maybe_Absent: - return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignNull() - case schema.Maybe_Value, schema.Maybe_Null: - panic("invalid state: cannot assign into assembler that's already finished") - } - panic("unreachable") -} -func (_Int__Assembler) AssignBool(bool) error { - return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignBool(false) +type _EncodedJOSE__KeyAssembler _EncodedJOSE__Assembler + +func (_EncodedJOSE__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.KeyAssembler"}.BeginMap(0) } -func (na *_Int__Assembler) AssignInt(v int64) error { - switch *na.m { - case schema.Maybe_Value, schema.Maybe_Null: - panic("invalid state: cannot assign into assembler that's already finished") - } - na.w.x = v - *na.m = schema.Maybe_Value - return nil +func (_EncodedJOSE__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.KeyAssembler"}.BeginList(0) } -func (_Int__Assembler) AssignFloat(float64) error { - return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignFloat(0) +func (na *_EncodedJOSE__KeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.KeyAssembler"}.AssignNull() } -func (_Int__Assembler) AssignString(string) error { - return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignString("") +func (_EncodedJOSE__KeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.KeyAssembler"}.AssignBool(false) } -func (_Int__Assembler) AssignBytes([]byte) error { - return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignBytes(nil) +func (_EncodedJOSE__KeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.KeyAssembler"}.AssignInt(0) } -func (_Int__Assembler) AssignLink(datamodel.Link) error { - return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignLink(nil) +func (_EncodedJOSE__KeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.KeyAssembler"}.AssignFloat(0) } -func (na *_Int__Assembler) AssignNode(v datamodel.Node) error { - if v.IsNull() { - return na.AssignNull() +func (ka *_EncodedJOSE__KeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") } - if v2, ok := v.(*_Int); ok { - switch *na.m { - case schema.Maybe_Value, schema.Maybe_Null: - panic("invalid state: cannot assign into assembler that's already finished") + switch k { + case "aad": + if ka.s&fieldBit__EncodedJOSE_Aad != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Aad} + } + ka.s += fieldBit__EncodedJOSE_Aad + ka.state = maState_expectValue + ka.f = 0 + return nil + case "ciphertext": + if ka.s&fieldBit__EncodedJOSE_Ciphertext != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Ciphertext} + } + ka.s += fieldBit__EncodedJOSE_Ciphertext + ka.state = maState_expectValue + ka.f = 1 + return nil + case "iv": + if ka.s&fieldBit__EncodedJOSE_Iv != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Iv} + } + ka.s += fieldBit__EncodedJOSE_Iv + ka.state = maState_expectValue + ka.f = 2 + return nil + case "link": + if ka.s&fieldBit__EncodedJOSE_Link != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Link} + } + ka.s += fieldBit__EncodedJOSE_Link + ka.state = maState_expectValue + ka.f = 3 + return nil + case "payload": + if ka.s&fieldBit__EncodedJOSE_Payload != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Payload} + } + ka.s += fieldBit__EncodedJOSE_Payload + ka.state = maState_expectValue + ka.f = 4 + return nil + case "protected": + if ka.s&fieldBit__EncodedJOSE_Protected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Protected} + } + ka.s += fieldBit__EncodedJOSE_Protected + ka.state = maState_expectValue + ka.f = 5 + return nil + case "recipients": + if ka.s&fieldBit__EncodedJOSE_Recipients != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Recipients} + } + ka.s += fieldBit__EncodedJOSE_Recipients + ka.state = maState_expectValue + ka.f = 6 + return nil + case "signatures": + if ka.s&fieldBit__EncodedJOSE_Signatures != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Signatures} + } + ka.s += fieldBit__EncodedJOSE_Signatures + ka.state = maState_expectValue + ka.f = 7 + return nil + case "tag": + if ka.s&fieldBit__EncodedJOSE_Tag != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Tag} + } + ka.s += fieldBit__EncodedJOSE_Tag + ka.state = maState_expectValue + ka.f = 8 + return nil + case "unprotected": + if ka.s&fieldBit__EncodedJOSE_Unprotected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Unprotected} } - *na.w = *v2 - *na.m = schema.Maybe_Value + ka.s += fieldBit__EncodedJOSE_Unprotected + ka.state = maState_expectValue + ka.f = 9 return nil + default: + return schema.ErrInvalidKey{TypeName: "dagjose.EncodedJOSE", Key: &_String{k}} } - if v2, err := v.AsInt(); err != nil { +} +func (_EncodedJOSE__KeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.KeyAssembler"}.AssignBytes(nil) +} +func (_EncodedJOSE__KeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.KeyAssembler"}.AssignLink(nil) +} +func (ka *_EncodedJOSE__KeyAssembler) AssignNode(v datamodel.Node) error { + if v2, err := v.AsString(); err != nil { return err } else { - return na.AssignInt(v2) + return ka.AssignString(v2) } } -func (_Int__Assembler) Prototype() datamodel.NodePrototype { - return _Int__Prototype{} +func (_EncodedJOSE__KeyAssembler) Prototype() datamodel.NodePrototype { + return _String__Prototype{} } -func (Int) Type() schema.Type { +func (EncodedJOSE) Type() schema.Type { return nil /*TODO:typelit*/ } -func (n Int) Representation() datamodel.Node { - return (*_Int__Repr)(n) -} - -type _Int__Repr = _Int - -var _ datamodel.Node = &_Int__Repr{} - -type _Int__ReprPrototype = _Int__Prototype -type _Int__ReprAssembler = _Int__Assembler - -func (n _JOSE) FieldAad() MaybeBase64Url { - return &n.aad -} -func (n _JOSE) FieldCiphertext() MaybeBase64Url { - return &n.ciphertext -} -func (n _JOSE) FieldIv() MaybeBase64Url { - return &n.iv -} -func (n _JOSE) FieldLink() MaybeLink { - return &n.link -} -func (n _JOSE) FieldPayload() MaybeBase64Url { - return &n.payload -} -func (n _JOSE) FieldProtected() MaybeBase64Url { - return &n.protected -} -func (n _JOSE) FieldRecipients() MaybeRecipients { - return &n.recipients -} -func (n _JOSE) FieldSignatures() MaybeSignatures { - return &n.signatures -} -func (n _JOSE) FieldTag() MaybeBase64Url { - return &n.tag -} -func (n _JOSE) FieldUnprotected() MaybeAny { - return &n.unprotected -} - -type _JOSE__Maybe struct { - m schema.Maybe - v JOSE +func (n EncodedJOSE) Representation() datamodel.Node { + return (*_EncodedJOSE__Repr)(n) } -type MaybeJOSE = *_JOSE__Maybe -func (m MaybeJOSE) IsNull() bool { - return m.m == schema.Maybe_Null -} -func (m MaybeJOSE) IsAbsent() bool { - return m.m == schema.Maybe_Absent -} -func (m MaybeJOSE) Exists() bool { - return m.m == schema.Maybe_Value -} -func (m MaybeJOSE) AsNode() datamodel.Node { - switch m.m { - case schema.Maybe_Absent: - return datamodel.Absent - case schema.Maybe_Null: - return datamodel.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") - } -} -func (m MaybeJOSE) Must() JOSE { - if !m.Exists() { - panic("unbox of a maybe rejected") - } - return m.v -} +type _EncodedJOSE__Repr _EncodedJOSE var ( - fieldName__JOSE_Aad = _String{"aad"} - fieldName__JOSE_Ciphertext = _String{"ciphertext"} - fieldName__JOSE_Iv = _String{"iv"} - fieldName__JOSE_Link = _String{"link"} - fieldName__JOSE_Payload = _String{"payload"} - fieldName__JOSE_Protected = _String{"protected"} - fieldName__JOSE_Recipients = _String{"recipients"} - fieldName__JOSE_Signatures = _String{"signatures"} - fieldName__JOSE_Tag = _String{"tag"} - fieldName__JOSE_Unprotected = _String{"unprotected"} + fieldName__EncodedJOSE_Aad_serial = _String{"aad"} + fieldName__EncodedJOSE_Ciphertext_serial = _String{"ciphertext"} + fieldName__EncodedJOSE_Iv_serial = _String{"iv"} + fieldName__EncodedJOSE_Link_serial = _String{"link"} + fieldName__EncodedJOSE_Payload_serial = _String{"payload"} + fieldName__EncodedJOSE_Protected_serial = _String{"protected"} + fieldName__EncodedJOSE_Recipients_serial = _String{"recipients"} + fieldName__EncodedJOSE_Signatures_serial = _String{"signatures"} + fieldName__EncodedJOSE_Tag_serial = _String{"tag"} + fieldName__EncodedJOSE_Unprotected_serial = _String{"unprotected"} ) -var _ datamodel.Node = (JOSE)(&_JOSE{}) -var _ schema.TypedNode = (JOSE)(&_JOSE{}) +var _ datamodel.Node = &_EncodedJOSE__Repr{} -func (JOSE) Kind() datamodel.Kind { +func (_EncodedJOSE__Repr) Kind() datamodel.Kind { return datamodel.Kind_Map } -func (n JOSE) LookupByString(key string) (datamodel.Node, error) { +func (n *_EncodedJOSE__Repr) LookupByString(key string) (datamodel.Node, error) { switch key { case "aad": if n.aad.m == schema.Maybe_Absent { - return datamodel.Absent, nil + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} } - return &n.aad.v, nil + return n.aad.v.Representation(), nil case "ciphertext": if n.ciphertext.m == schema.Maybe_Absent { - return datamodel.Absent, nil + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} } - return &n.ciphertext.v, nil + return n.ciphertext.v.Representation(), nil case "iv": if n.iv.m == schema.Maybe_Absent { - return datamodel.Absent, nil + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} } - return &n.iv.v, nil + return n.iv.v.Representation(), nil case "link": if n.link.m == schema.Maybe_Absent { - return datamodel.Absent, nil + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} } - return &n.link.v, nil + return n.link.v.Representation(), nil case "payload": if n.payload.m == schema.Maybe_Absent { - return datamodel.Absent, nil + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} } - return &n.payload.v, nil + return n.payload.v.Representation(), nil case "protected": if n.protected.m == schema.Maybe_Absent { - return datamodel.Absent, nil + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} } - return &n.protected.v, nil + return n.protected.v.Representation(), nil case "recipients": if n.recipients.m == schema.Maybe_Absent { - return datamodel.Absent, nil + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} } - return &n.recipients.v, nil + return n.recipients.v.Representation(), nil case "signatures": if n.signatures.m == schema.Maybe_Absent { - return datamodel.Absent, nil + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} } - return &n.signatures.v, nil + return n.signatures.v.Representation(), nil case "tag": if n.tag.m == schema.Maybe_Absent { - return datamodel.Absent, nil + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} } - return &n.tag.v, nil + return n.tag.v.Representation(), nil case "unprotected": if n.unprotected.m == schema.Maybe_Absent { - return datamodel.Absent, nil + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} } - return n.unprotected.v, nil + return n.unprotected.v.Representation(), nil default: return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} } } -func (n JOSE) LookupByNode(key datamodel.Node) (datamodel.Node, error) { +func (n *_EncodedJOSE__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) { ks, err := key.AsString() if err != nil { return nil, err } return n.LookupByString(ks) } -func (JOSE) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Map{TypeName: "dagjose.JOSE"}.LookupByIndex(0) +func (_EncodedJOSE__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE.Repr"}.LookupByIndex(0) } -func (n JOSE) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { +func (n _EncodedJOSE__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { return n.LookupByString(seg.String()) } -func (n JOSE) MapIterator() datamodel.MapIterator { - return &_JOSE__MapItr{n, 0} +func (n *_EncodedJOSE__Repr) MapIterator() datamodel.MapIterator { + end := 10 + if n.unprotected.m == schema.Maybe_Absent { + end = 9 + } else { + goto done + } + if n.tag.m == schema.Maybe_Absent { + end = 8 + } else { + goto done + } + if n.signatures.m == schema.Maybe_Absent { + end = 7 + } else { + goto done + } + if n.recipients.m == schema.Maybe_Absent { + end = 6 + } else { + goto done + } + if n.protected.m == schema.Maybe_Absent { + end = 5 + } else { + goto done + } + if n.payload.m == schema.Maybe_Absent { + end = 4 + } else { + goto done + } + if n.link.m == schema.Maybe_Absent { + end = 3 + } else { + goto done + } + if n.iv.m == schema.Maybe_Absent { + end = 2 + } else { + goto done + } + if n.ciphertext.m == schema.Maybe_Absent { + end = 1 + } else { + goto done + } + if n.aad.m == schema.Maybe_Absent { + end = 0 + } else { + goto done + } +done: + return &_EncodedJOSE__ReprMapItr{n, 0, end} } -type _JOSE__MapItr struct { - n JOSE +type _EncodedJOSE__ReprMapItr struct { + n *_EncodedJOSE__Repr idx int + end int } -func (itr *_JOSE__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { +func (itr *_EncodedJOSE__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { +advance: if itr.idx >= 10 { return nil, nil, datamodel.ErrIteratorOverread{} } switch itr.idx { case 0: - k = &fieldName__JOSE_Aad + k = &fieldName__EncodedJOSE_Aad_serial if itr.n.aad.m == schema.Maybe_Absent { - v = datamodel.Absent - break + itr.idx++ + goto advance } - v = &itr.n.aad.v + v = itr.n.aad.v.Representation() case 1: - k = &fieldName__JOSE_Ciphertext + k = &fieldName__EncodedJOSE_Ciphertext_serial if itr.n.ciphertext.m == schema.Maybe_Absent { - v = datamodel.Absent - break + itr.idx++ + goto advance } - v = &itr.n.ciphertext.v + v = itr.n.ciphertext.v.Representation() case 2: - k = &fieldName__JOSE_Iv + k = &fieldName__EncodedJOSE_Iv_serial if itr.n.iv.m == schema.Maybe_Absent { - v = datamodel.Absent - break + itr.idx++ + goto advance } - v = &itr.n.iv.v + v = itr.n.iv.v.Representation() case 3: - k = &fieldName__JOSE_Link + k = &fieldName__EncodedJOSE_Link_serial if itr.n.link.m == schema.Maybe_Absent { - v = datamodel.Absent - break + itr.idx++ + goto advance } - v = &itr.n.link.v + v = itr.n.link.v.Representation() case 4: - k = &fieldName__JOSE_Payload + k = &fieldName__EncodedJOSE_Payload_serial if itr.n.payload.m == schema.Maybe_Absent { - v = datamodel.Absent - break + itr.idx++ + goto advance } - v = &itr.n.payload.v + v = itr.n.payload.v.Representation() case 5: - k = &fieldName__JOSE_Protected + k = &fieldName__EncodedJOSE_Protected_serial if itr.n.protected.m == schema.Maybe_Absent { - v = datamodel.Absent - break + itr.idx++ + goto advance } - v = &itr.n.protected.v + v = itr.n.protected.v.Representation() case 6: - k = &fieldName__JOSE_Recipients + k = &fieldName__EncodedJOSE_Recipients_serial if itr.n.recipients.m == schema.Maybe_Absent { - v = datamodel.Absent - break + itr.idx++ + goto advance } - v = &itr.n.recipients.v + v = itr.n.recipients.v.Representation() case 7: - k = &fieldName__JOSE_Signatures + k = &fieldName__EncodedJOSE_Signatures_serial if itr.n.signatures.m == schema.Maybe_Absent { - v = datamodel.Absent - break + itr.idx++ + goto advance } - v = &itr.n.signatures.v + v = itr.n.signatures.v.Representation() case 8: - k = &fieldName__JOSE_Tag + k = &fieldName__EncodedJOSE_Tag_serial if itr.n.tag.m == schema.Maybe_Absent { - v = datamodel.Absent - break + itr.idx++ + goto advance } - v = &itr.n.tag.v + v = itr.n.tag.v.Representation() case 9: - k = &fieldName__JOSE_Unprotected + k = &fieldName__EncodedJOSE_Unprotected_serial if itr.n.unprotected.m == schema.Maybe_Absent { - v = datamodel.Absent - break + itr.idx++ + goto advance } - v = itr.n.unprotected.v + v = itr.n.unprotected.v.Representation() default: panic("unreachable") } itr.idx++ return } -func (itr *_JOSE__MapItr) Done() bool { - return itr.idx >= 10 +func (itr *_EncodedJOSE__ReprMapItr) Done() bool { + return itr.idx >= itr.end } - -func (JOSE) ListIterator() datamodel.ListIterator { +func (_EncodedJOSE__Repr) ListIterator() datamodel.ListIterator { return nil } -func (JOSE) Length() int64 { - return 10 +func (rn *_EncodedJOSE__Repr) Length() int64 { + l := 10 + if rn.aad.m == schema.Maybe_Absent { + l-- + } + if rn.ciphertext.m == schema.Maybe_Absent { + l-- + } + if rn.iv.m == schema.Maybe_Absent { + l-- + } + if rn.link.m == schema.Maybe_Absent { + l-- + } + if rn.payload.m == schema.Maybe_Absent { + l-- + } + if rn.protected.m == schema.Maybe_Absent { + l-- + } + if rn.recipients.m == schema.Maybe_Absent { + l-- + } + if rn.signatures.m == schema.Maybe_Absent { + l-- + } + if rn.tag.m == schema.Maybe_Absent { + l-- + } + if rn.unprotected.m == schema.Maybe_Absent { + l-- + } + return int64(l) } -func (JOSE) IsAbsent() bool { +func (_EncodedJOSE__Repr) IsAbsent() bool { return false } -func (JOSE) IsNull() bool { +func (_EncodedJOSE__Repr) IsNull() bool { return false } -func (JOSE) AsBool() (bool, error) { - return mixins.Map{TypeName: "dagjose.JOSE"}.AsBool() +func (_EncodedJOSE__Repr) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE.Repr"}.AsBool() } -func (JOSE) AsInt() (int64, error) { - return mixins.Map{TypeName: "dagjose.JOSE"}.AsInt() +func (_EncodedJOSE__Repr) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE.Repr"}.AsInt() } -func (JOSE) AsFloat() (float64, error) { - return mixins.Map{TypeName: "dagjose.JOSE"}.AsFloat() +func (_EncodedJOSE__Repr) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE.Repr"}.AsFloat() } -func (JOSE) AsString() (string, error) { - return mixins.Map{TypeName: "dagjose.JOSE"}.AsString() +func (_EncodedJOSE__Repr) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE.Repr"}.AsString() } -func (JOSE) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "dagjose.JOSE"}.AsBytes() +func (_EncodedJOSE__Repr) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE.Repr"}.AsBytes() } -func (JOSE) AsLink() (datamodel.Link, error) { - return mixins.Map{TypeName: "dagjose.JOSE"}.AsLink() +func (_EncodedJOSE__Repr) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.EncodedJOSE.Repr"}.AsLink() } -func (JOSE) Prototype() datamodel.NodePrototype { - return _JOSE__Prototype{} +func (_EncodedJOSE__Repr) Prototype() datamodel.NodePrototype { + return _EncodedJOSE__ReprPrototype{} } -type _JOSE__Prototype struct{} +type _EncodedJOSE__ReprPrototype struct{} -func (_JOSE__Prototype) NewBuilder() datamodel.NodeBuilder { - var nb _JOSE__Builder +func (_EncodedJOSE__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _EncodedJOSE__ReprBuilder nb.Reset() return &nb } -type _JOSE__Builder struct { - _JOSE__Assembler +type _EncodedJOSE__ReprBuilder struct { + _EncodedJOSE__ReprAssembler } -func (nb *_JOSE__Builder) Build() datamodel.Node { +func (nb *_EncodedJOSE__ReprBuilder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_JOSE__Builder) Reset() { - var w _JOSE +func (nb *_EncodedJOSE__ReprBuilder) Reset() { + var w _EncodedJOSE var m schema.Maybe - *nb = _JOSE__Builder{_JOSE__Assembler{w: &w, m: &m}} + *nb = _EncodedJOSE__ReprBuilder{_EncodedJOSE__ReprAssembler{w: &w, m: &m}} } -type _JOSE__Assembler struct { - w *_JOSE +type _EncodedJOSE__ReprAssembler struct { + w *_EncodedJOSE m *schema.Maybe state maState s int f int cm schema.Maybe - ca_aad _Base64Url__Assembler - ca_ciphertext _Base64Url__Assembler - ca_iv _Base64Url__Assembler - ca_link _Link__Assembler - ca_payload _Base64Url__Assembler - ca_protected _Base64Url__Assembler - ca_recipients _Recipients__Assembler - ca_signatures _Signatures__Assembler - ca_tag _Base64Url__Assembler - ca_unprotected _Any__Assembler + ca_aad _Raw__ReprAssembler + ca_ciphertext _Raw__ReprAssembler + ca_iv _Raw__ReprAssembler + ca_link _Link__ReprAssembler + ca_payload _Raw__ReprAssembler + ca_protected _Raw__ReprAssembler + ca_recipients _EncodedRecipients__ReprAssembler + ca_signatures _EncodedSignatures__ReprAssembler + ca_tag _Raw__ReprAssembler + ca_unprotected _Any__ReprAssembler } -func (na *_JOSE__Assembler) reset() { +func (na *_EncodedJOSE__ReprAssembler) reset() { na.state = maState_initial na.s = 0 na.ca_aad.reset() @@ -2027,22 +7497,7 @@ func (na *_JOSE__Assembler) reset() { na.ca_tag.reset() na.ca_unprotected.reset() } - -var ( - fieldBit__JOSE_Aad = 1 << 0 - fieldBit__JOSE_Ciphertext = 1 << 1 - fieldBit__JOSE_Iv = 1 << 2 - fieldBit__JOSE_Link = 1 << 3 - fieldBit__JOSE_Payload = 1 << 4 - fieldBit__JOSE_Protected = 1 << 5 - fieldBit__JOSE_Recipients = 1 << 6 - fieldBit__JOSE_Signatures = 1 << 7 - fieldBit__JOSE_Tag = 1 << 8 - fieldBit__JOSE_Unprotected = 1 << 9 - fieldBits__JOSE_sufficient = 0 -) - -func (na *_JOSE__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) { +func (na *_EncodedJOSE__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -2051,20 +7506,20 @@ func (na *_JOSE__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) { } *na.m = midvalue if na.w == nil { - na.w = &_JOSE{} + na.w = &_EncodedJOSE{} } return na, nil } -func (_JOSE__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.MapAssembler{TypeName: "dagjose.JOSE"}.BeginList(0) +func (_EncodedJOSE__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE.Repr"}.BeginList(0) } -func (na *_JOSE__Assembler) AssignNull() error { +func (na *_EncodedJOSE__ReprAssembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{TypeName: "dagjose.JOSE"}.AssignNull() + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -2072,29 +7527,29 @@ func (na *_JOSE__Assembler) AssignNull() error { } panic("unreachable") } -func (_JOSE__Assembler) AssignBool(bool) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE"}.AssignBool(false) +func (_EncodedJOSE__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE.Repr"}.AssignBool(false) } -func (_JOSE__Assembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE"}.AssignInt(0) +func (_EncodedJOSE__ReprAssembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE.Repr"}.AssignInt(0) } -func (_JOSE__Assembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE"}.AssignFloat(0) +func (_EncodedJOSE__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE.Repr"}.AssignFloat(0) } -func (_JOSE__Assembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE"}.AssignString("") +func (_EncodedJOSE__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE.Repr"}.AssignString("") } -func (_JOSE__Assembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE"}.AssignBytes(nil) +func (_EncodedJOSE__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE.Repr"}.AssignBytes(nil) } -func (_JOSE__Assembler) AssignLink(datamodel.Link) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE"}.AssignLink(nil) +func (_EncodedJOSE__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedJOSE.Repr"}.AssignLink(nil) } -func (na *_JOSE__Assembler) AssignNode(v datamodel.Node) error { +func (na *_EncodedJOSE__ReprAssembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_JOSE); ok { + if v2, ok := v.(*_EncodedJOSE); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -2111,7 +7566,7 @@ func (na *_JOSE__Assembler) AssignNode(v datamodel.Node) error { return nil } if v.Kind() != datamodel.Kind_Map { - return datamodel.ErrWrongKind{TypeName: "dagjose.JOSE", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + return datamodel.ErrWrongKind{TypeName: "dagjose.EncodedJOSE.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} } itr := v.MapIterator() for !itr.Done() { @@ -2128,10 +7583,10 @@ func (na *_JOSE__Assembler) AssignNode(v datamodel.Node) error { } return na.Finish() } -func (_JOSE__Assembler) Prototype() datamodel.NodePrototype { - return _JOSE__Prototype{} +func (_EncodedJOSE__ReprAssembler) Prototype() datamodel.NodePrototype { + return _EncodedJOSE__ReprPrototype{} } -func (ma *_JOSE__Assembler) valueFinishTidy() bool { +func (ma *_EncodedJOSE__ReprAssembler) valueFinishTidy() bool { switch ma.f { case 0: switch ma.w.aad.m { @@ -2218,7 +7673,7 @@ func (ma *_JOSE__Assembler) valueFinishTidy() bool { panic("unreachable") } } -func (ma *_JOSE__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { +func (ma *_EncodedJOSE__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { switch ma.state { case maState_initial: // carry on @@ -2235,109 +7690,120 @@ func (ma *_JOSE__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, er } switch k { case "aad": - if ma.s&fieldBit__JOSE_Aad != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Aad} + if ma.s&fieldBit__EncodedJOSE_Aad != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Aad_serial} } - ma.s += fieldBit__JOSE_Aad + ma.s += fieldBit__EncodedJOSE_Aad ma.state = maState_midValue ma.f = 0 ma.ca_aad.w = &ma.w.aad.v ma.ca_aad.m = &ma.w.aad.m + return &ma.ca_aad, nil case "ciphertext": - if ma.s&fieldBit__JOSE_Ciphertext != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Ciphertext} + if ma.s&fieldBit__EncodedJOSE_Ciphertext != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Ciphertext_serial} } - ma.s += fieldBit__JOSE_Ciphertext + ma.s += fieldBit__EncodedJOSE_Ciphertext ma.state = maState_midValue ma.f = 1 ma.ca_ciphertext.w = &ma.w.ciphertext.v ma.ca_ciphertext.m = &ma.w.ciphertext.m + return &ma.ca_ciphertext, nil case "iv": - if ma.s&fieldBit__JOSE_Iv != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Iv} + if ma.s&fieldBit__EncodedJOSE_Iv != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Iv_serial} } - ma.s += fieldBit__JOSE_Iv + ma.s += fieldBit__EncodedJOSE_Iv ma.state = maState_midValue ma.f = 2 ma.ca_iv.w = &ma.w.iv.v ma.ca_iv.m = &ma.w.iv.m + return &ma.ca_iv, nil case "link": - if ma.s&fieldBit__JOSE_Link != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Link} + if ma.s&fieldBit__EncodedJOSE_Link != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Link_serial} } - ma.s += fieldBit__JOSE_Link + ma.s += fieldBit__EncodedJOSE_Link ma.state = maState_midValue ma.f = 3 ma.ca_link.w = &ma.w.link.v ma.ca_link.m = &ma.w.link.m + return &ma.ca_link, nil case "payload": - if ma.s&fieldBit__JOSE_Payload != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Payload} + if ma.s&fieldBit__EncodedJOSE_Payload != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Payload_serial} } - ma.s += fieldBit__JOSE_Payload + ma.s += fieldBit__EncodedJOSE_Payload ma.state = maState_midValue ma.f = 4 ma.ca_payload.w = &ma.w.payload.v ma.ca_payload.m = &ma.w.payload.m + return &ma.ca_payload, nil case "protected": - if ma.s&fieldBit__JOSE_Protected != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Protected} + if ma.s&fieldBit__EncodedJOSE_Protected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Protected_serial} } - ma.s += fieldBit__JOSE_Protected + ma.s += fieldBit__EncodedJOSE_Protected ma.state = maState_midValue ma.f = 5 ma.ca_protected.w = &ma.w.protected.v ma.ca_protected.m = &ma.w.protected.m + return &ma.ca_protected, nil case "recipients": - if ma.s&fieldBit__JOSE_Recipients != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Recipients} + if ma.s&fieldBit__EncodedJOSE_Recipients != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Recipients_serial} } - ma.s += fieldBit__JOSE_Recipients + ma.s += fieldBit__EncodedJOSE_Recipients ma.state = maState_midValue ma.f = 6 ma.ca_recipients.w = &ma.w.recipients.v ma.ca_recipients.m = &ma.w.recipients.m + return &ma.ca_recipients, nil case "signatures": - if ma.s&fieldBit__JOSE_Signatures != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Signatures} + if ma.s&fieldBit__EncodedJOSE_Signatures != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Signatures_serial} } - ma.s += fieldBit__JOSE_Signatures + ma.s += fieldBit__EncodedJOSE_Signatures ma.state = maState_midValue ma.f = 7 ma.ca_signatures.w = &ma.w.signatures.v ma.ca_signatures.m = &ma.w.signatures.m + return &ma.ca_signatures, nil case "tag": - if ma.s&fieldBit__JOSE_Tag != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Tag} + if ma.s&fieldBit__EncodedJOSE_Tag != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Tag_serial} } - ma.s += fieldBit__JOSE_Tag + ma.s += fieldBit__EncodedJOSE_Tag ma.state = maState_midValue ma.f = 8 ma.ca_tag.w = &ma.w.tag.v ma.ca_tag.m = &ma.w.tag.m + return &ma.ca_tag, nil case "unprotected": - if ma.s&fieldBit__JOSE_Unprotected != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Unprotected} + if ma.s&fieldBit__EncodedJOSE_Unprotected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Unprotected_serial} } - ma.s += fieldBit__JOSE_Unprotected + ma.s += fieldBit__EncodedJOSE_Unprotected ma.state = maState_midValue ma.f = 9 ma.ca_unprotected.w = ma.w.unprotected.v ma.ca_unprotected.m = &ma.w.unprotected.m + return &ma.ca_unprotected, nil + default: } - return nil, schema.ErrInvalidKey{TypeName: "dagjose.JOSE", Key: &_String{k}} + return nil, schema.ErrInvalidKey{TypeName: "dagjose.EncodedJOSE.Repr", Key: &_String{k}} } -func (ma *_JOSE__Assembler) AssembleKey() datamodel.NodeAssembler { +func (ma *_EncodedJOSE__ReprAssembler) AssembleKey() datamodel.NodeAssembler { switch ma.state { case maState_initial: // carry on @@ -2353,9 +7819,9 @@ func (ma *_JOSE__Assembler) AssembleKey() datamodel.NodeAssembler { panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") } ma.state = maState_midKey - return (*_JOSE__KeyAssembler)(ma) + return (*_EncodedJOSE__ReprKeyAssembler)(ma) } -func (ma *_JOSE__Assembler) AssembleValue() datamodel.NodeAssembler { +func (ma *_EncodedJOSE__ReprAssembler) AssembleValue() datamodel.NodeAssembler { switch ma.state { case maState_initial: panic("invalid state: AssembleValue cannot be called when no key is primed") @@ -2373,48 +7839,58 @@ func (ma *_JOSE__Assembler) AssembleValue() datamodel.NodeAssembler { case 0: ma.ca_aad.w = &ma.w.aad.v ma.ca_aad.m = &ma.w.aad.m + return &ma.ca_aad case 1: ma.ca_ciphertext.w = &ma.w.ciphertext.v ma.ca_ciphertext.m = &ma.w.ciphertext.m + return &ma.ca_ciphertext case 2: ma.ca_iv.w = &ma.w.iv.v ma.ca_iv.m = &ma.w.iv.m + return &ma.ca_iv case 3: ma.ca_link.w = &ma.w.link.v ma.ca_link.m = &ma.w.link.m + return &ma.ca_link case 4: ma.ca_payload.w = &ma.w.payload.v ma.ca_payload.m = &ma.w.payload.m + return &ma.ca_payload case 5: ma.ca_protected.w = &ma.w.protected.v ma.ca_protected.m = &ma.w.protected.m + return &ma.ca_protected case 6: ma.ca_recipients.w = &ma.w.recipients.v ma.ca_recipients.m = &ma.w.recipients.m + return &ma.ca_recipients case 7: ma.ca_signatures.w = &ma.w.signatures.v ma.ca_signatures.m = &ma.w.signatures.m + return &ma.ca_signatures case 8: ma.ca_tag.w = &ma.w.tag.v ma.ca_tag.m = &ma.w.tag.m + return &ma.ca_tag case 9: ma.ca_unprotected.w = ma.w.unprotected.v ma.ca_unprotected.m = &ma.w.unprotected.m + return &ma.ca_unprotected default: panic("unreachable") } } -func (ma *_JOSE__Assembler) Finish() error { +func (ma *_EncodedJOSE__ReprAssembler) Finish() error { switch ma.state { case maState_initial: // carry on @@ -2429,7 +7905,7 @@ func (ma *_JOSE__Assembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s&fieldBits__JOSE_sufficient != fieldBits__JOSE_sufficient { + if ma.s&fieldBits__EncodedJOSE_sufficient != fieldBits__EncodedJOSE_sufficient { err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} return err } @@ -2437,504 +7913,340 @@ func (ma *_JOSE__Assembler) Finish() error { *ma.m = schema.Maybe_Value return nil } -func (ma *_JOSE__Assembler) KeyPrototype() datamodel.NodePrototype { +func (ma *_EncodedJOSE__ReprAssembler) KeyPrototype() datamodel.NodePrototype { return _String__Prototype{} } -func (ma *_JOSE__Assembler) ValuePrototype(k string) datamodel.NodePrototype { - panic("todo structbuilder mapassembler valueprototype") +func (ma *_EncodedJOSE__ReprAssembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler repr valueprototype") } -type _JOSE__KeyAssembler _JOSE__Assembler +type _EncodedJOSE__ReprKeyAssembler _EncodedJOSE__ReprAssembler -func (_JOSE__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.KeyAssembler"}.BeginMap(0) +func (_EncodedJOSE__ReprKeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.Repr.KeyAssembler"}.BeginMap(0) } -func (_JOSE__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.KeyAssembler"}.BeginList(0) +func (_EncodedJOSE__ReprKeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.Repr.KeyAssembler"}.BeginList(0) } -func (na *_JOSE__KeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.KeyAssembler"}.AssignNull() +func (na *_EncodedJOSE__ReprKeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.Repr.KeyAssembler"}.AssignNull() } -func (_JOSE__KeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.KeyAssembler"}.AssignBool(false) +func (_EncodedJOSE__ReprKeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.Repr.KeyAssembler"}.AssignBool(false) } -func (_JOSE__KeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.KeyAssembler"}.AssignInt(0) +func (_EncodedJOSE__ReprKeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.Repr.KeyAssembler"}.AssignInt(0) } -func (_JOSE__KeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.KeyAssembler"}.AssignFloat(0) +func (_EncodedJOSE__ReprKeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.Repr.KeyAssembler"}.AssignFloat(0) } -func (ka *_JOSE__KeyAssembler) AssignString(k string) error { +func (ka *_EncodedJOSE__ReprKeyAssembler) AssignString(k string) error { if ka.state != maState_midKey { panic("misuse: KeyAssembler held beyond its valid lifetime") } switch k { case "aad": - if ka.s&fieldBit__JOSE_Aad != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Aad} + if ka.s&fieldBit__EncodedJOSE_Aad != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Aad_serial} } - ka.s += fieldBit__JOSE_Aad + ka.s += fieldBit__EncodedJOSE_Aad ka.state = maState_expectValue ka.f = 0 return nil case "ciphertext": - if ka.s&fieldBit__JOSE_Ciphertext != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Ciphertext} + if ka.s&fieldBit__EncodedJOSE_Ciphertext != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Ciphertext_serial} } - ka.s += fieldBit__JOSE_Ciphertext + ka.s += fieldBit__EncodedJOSE_Ciphertext ka.state = maState_expectValue ka.f = 1 return nil case "iv": - if ka.s&fieldBit__JOSE_Iv != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Iv} + if ka.s&fieldBit__EncodedJOSE_Iv != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Iv_serial} } - ka.s += fieldBit__JOSE_Iv + ka.s += fieldBit__EncodedJOSE_Iv ka.state = maState_expectValue ka.f = 2 return nil case "link": - if ka.s&fieldBit__JOSE_Link != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Link} + if ka.s&fieldBit__EncodedJOSE_Link != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Link_serial} } - ka.s += fieldBit__JOSE_Link + ka.s += fieldBit__EncodedJOSE_Link ka.state = maState_expectValue ka.f = 3 return nil case "payload": - if ka.s&fieldBit__JOSE_Payload != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Payload} + if ka.s&fieldBit__EncodedJOSE_Payload != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Payload_serial} } - ka.s += fieldBit__JOSE_Payload + ka.s += fieldBit__EncodedJOSE_Payload ka.state = maState_expectValue ka.f = 4 return nil case "protected": - if ka.s&fieldBit__JOSE_Protected != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Protected} + if ka.s&fieldBit__EncodedJOSE_Protected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Protected_serial} } - ka.s += fieldBit__JOSE_Protected + ka.s += fieldBit__EncodedJOSE_Protected ka.state = maState_expectValue ka.f = 5 return nil case "recipients": - if ka.s&fieldBit__JOSE_Recipients != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Recipients} + if ka.s&fieldBit__EncodedJOSE_Recipients != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Recipients_serial} } - ka.s += fieldBit__JOSE_Recipients + ka.s += fieldBit__EncodedJOSE_Recipients ka.state = maState_expectValue ka.f = 6 return nil case "signatures": - if ka.s&fieldBit__JOSE_Signatures != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Signatures} + if ka.s&fieldBit__EncodedJOSE_Signatures != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Signatures_serial} } - ka.s += fieldBit__JOSE_Signatures + ka.s += fieldBit__EncodedJOSE_Signatures ka.state = maState_expectValue ka.f = 7 return nil case "tag": - if ka.s&fieldBit__JOSE_Tag != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Tag} + if ka.s&fieldBit__EncodedJOSE_Tag != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Tag_serial} } - ka.s += fieldBit__JOSE_Tag + ka.s += fieldBit__EncodedJOSE_Tag ka.state = maState_expectValue ka.f = 8 return nil case "unprotected": - if ka.s&fieldBit__JOSE_Unprotected != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Unprotected} + if ka.s&fieldBit__EncodedJOSE_Unprotected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedJOSE_Unprotected_serial} } - ka.s += fieldBit__JOSE_Unprotected + ka.s += fieldBit__EncodedJOSE_Unprotected ka.state = maState_expectValue ka.f = 9 return nil - default: - return schema.ErrInvalidKey{TypeName: "dagjose.JOSE", Key: &_String{k}} } + return schema.ErrInvalidKey{TypeName: "dagjose.EncodedJOSE.Repr", Key: &_String{k}} } -func (_JOSE__KeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.KeyAssembler"}.AssignBytes(nil) +func (_EncodedJOSE__ReprKeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.Repr.KeyAssembler"}.AssignBytes(nil) } -func (_JOSE__KeyAssembler) AssignLink(datamodel.Link) error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.KeyAssembler"}.AssignLink(nil) +func (_EncodedJOSE__ReprKeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedJOSE.Repr.KeyAssembler"}.AssignLink(nil) } -func (ka *_JOSE__KeyAssembler) AssignNode(v datamodel.Node) error { +func (ka *_EncodedJOSE__ReprKeyAssembler) AssignNode(v datamodel.Node) error { if v2, err := v.AsString(); err != nil { return err } else { return ka.AssignString(v2) } } -func (_JOSE__KeyAssembler) Prototype() datamodel.NodePrototype { +func (_EncodedJOSE__ReprKeyAssembler) Prototype() datamodel.NodePrototype { return _String__Prototype{} } -func (JOSE) Type() schema.Type { - return nil /*TODO:typelit*/ + +func (n _EncodedRecipient) FieldHeader() MaybeAny { + return &n.header } -func (n JOSE) Representation() datamodel.Node { - return (*_JOSE__Repr)(n) +func (n _EncodedRecipient) FieldEncrypted_key() MaybeRaw { + return &n.encrypted_key } -type _JOSE__Repr _JOSE - -var ( - fieldName__JOSE_Aad_serial = _String{"aad"} - fieldName__JOSE_Ciphertext_serial = _String{"ciphertext"} - fieldName__JOSE_Iv_serial = _String{"iv"} - fieldName__JOSE_Link_serial = _String{"link"} - fieldName__JOSE_Payload_serial = _String{"payload"} - fieldName__JOSE_Protected_serial = _String{"protected"} - fieldName__JOSE_Recipients_serial = _String{"recipients"} - fieldName__JOSE_Signatures_serial = _String{"signatures"} - fieldName__JOSE_Tag_serial = _String{"tag"} - fieldName__JOSE_Unprotected_serial = _String{"unprotected"} -) -var _ datamodel.Node = &_JOSE__Repr{} - -func (_JOSE__Repr) Kind() datamodel.Kind { - return datamodel.Kind_Map -} -func (n *_JOSE__Repr) LookupByString(key string) (datamodel.Node, error) { - switch key { - case "aad": - if n.aad.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.aad.v.Representation(), nil - case "ciphertext": - if n.ciphertext.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.ciphertext.v.Representation(), nil - case "iv": - if n.iv.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.iv.v.Representation(), nil - case "link": - if n.link.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.link.v.Representation(), nil - case "payload": - if n.payload.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.payload.v.Representation(), nil - case "protected": - if n.protected.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.protected.v.Representation(), nil - case "recipients": - if n.recipients.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.recipients.v.Representation(), nil - case "signatures": - if n.signatures.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.signatures.v.Representation(), nil - case "tag": - if n.tag.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.tag.v.Representation(), nil - case "unprotected": - if n.unprotected.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.unprotected.v.Representation(), nil - default: - return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} - } +type _EncodedRecipient__Maybe struct { + m schema.Maybe + v EncodedRecipient } -func (n *_JOSE__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) { - ks, err := key.AsString() - if err != nil { - return nil, err - } - return n.LookupByString(ks) +type MaybeEncodedRecipient = *_EncodedRecipient__Maybe + +func (m MaybeEncodedRecipient) IsNull() bool { + return m.m == schema.Maybe_Null } -func (_JOSE__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Map{TypeName: "dagjose.JOSE.Repr"}.LookupByIndex(0) +func (m MaybeEncodedRecipient) IsAbsent() bool { + return m.m == schema.Maybe_Absent } -func (n _JOSE__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - return n.LookupByString(seg.String()) +func (m MaybeEncodedRecipient) Exists() bool { + return m.m == schema.Maybe_Value } -func (n *_JOSE__Repr) MapIterator() datamodel.MapIterator { - end := 10 - if n.unprotected.m == schema.Maybe_Absent { - end = 9 - } else { - goto done - } - if n.tag.m == schema.Maybe_Absent { - end = 8 - } else { - goto done - } - if n.signatures.m == schema.Maybe_Absent { - end = 7 - } else { - goto done - } - if n.recipients.m == schema.Maybe_Absent { - end = 6 - } else { - goto done - } - if n.protected.m == schema.Maybe_Absent { - end = 5 - } else { - goto done - } - if n.payload.m == schema.Maybe_Absent { - end = 4 - } else { - goto done - } - if n.link.m == schema.Maybe_Absent { - end = 3 - } else { - goto done - } - if n.iv.m == schema.Maybe_Absent { - end = 2 - } else { - goto done - } - if n.ciphertext.m == schema.Maybe_Absent { - end = 1 - } else { - goto done +func (m MaybeEncodedRecipient) AsNode() datamodel.Node { + switch m.m { + case schema.Maybe_Absent: + return datamodel.Absent + case schema.Maybe_Null: + return datamodel.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } - if n.aad.m == schema.Maybe_Absent { - end = 0 - } else { - goto done +} +func (m MaybeEncodedRecipient) Must() EncodedRecipient { + if !m.Exists() { + panic("unbox of a maybe rejected") } -done: - return &_JOSE__ReprMapItr{n, 0, end} + return m.v } -type _JOSE__ReprMapItr struct { - n *_JOSE__Repr - idx int - end int -} +var ( + fieldName__EncodedRecipient_Header = _String{"header"} + fieldName__EncodedRecipient_Encrypted_key = _String{"encrypted_key"} +) +var _ datamodel.Node = (EncodedRecipient)(&_EncodedRecipient{}) +var _ schema.TypedNode = (EncodedRecipient)(&_EncodedRecipient{}) -func (itr *_JOSE__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { -advance: - if itr.idx >= 10 { - return nil, nil, datamodel.ErrIteratorOverread{} - } - switch itr.idx { - case 0: - k = &fieldName__JOSE_Aad_serial - if itr.n.aad.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.aad.v.Representation() - case 1: - k = &fieldName__JOSE_Ciphertext_serial - if itr.n.ciphertext.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.ciphertext.v.Representation() - case 2: - k = &fieldName__JOSE_Iv_serial - if itr.n.iv.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.iv.v.Representation() - case 3: - k = &fieldName__JOSE_Link_serial - if itr.n.link.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.link.v.Representation() - case 4: - k = &fieldName__JOSE_Payload_serial - if itr.n.payload.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.payload.v.Representation() - case 5: - k = &fieldName__JOSE_Protected_serial - if itr.n.protected.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.protected.v.Representation() - case 6: - k = &fieldName__JOSE_Recipients_serial - if itr.n.recipients.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.recipients.v.Representation() - case 7: - k = &fieldName__JOSE_Signatures_serial - if itr.n.signatures.m == schema.Maybe_Absent { - itr.idx++ - goto advance +func (EncodedRecipient) Kind() datamodel.Kind { + return datamodel.Kind_Map +} +func (n EncodedRecipient) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "header": + if n.header.m == schema.Maybe_Absent { + return datamodel.Absent, nil } - v = itr.n.signatures.v.Representation() - case 8: - k = &fieldName__JOSE_Tag_serial - if itr.n.tag.m == schema.Maybe_Absent { - itr.idx++ - goto advance + return n.header.v, nil + case "encrypted_key": + if n.encrypted_key.m == schema.Maybe_Absent { + return datamodel.Absent, nil } - v = itr.n.tag.v.Representation() - case 9: - k = &fieldName__JOSE_Unprotected_serial - if itr.n.unprotected.m == schema.Maybe_Absent { - itr.idx++ - goto advance + return &n.encrypted_key.v, nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} + } +} +func (n EncodedRecipient) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (EncodedRecipient) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient"}.LookupByIndex(0) +} +func (n EncodedRecipient) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) +} +func (n EncodedRecipient) MapIterator() datamodel.MapIterator { + return &_EncodedRecipient__MapItr{n, 0} +} + +type _EncodedRecipient__MapItr struct { + n EncodedRecipient + idx int +} + +func (itr *_EncodedRecipient__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { + if itr.idx >= 2 { + return nil, nil, datamodel.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__EncodedRecipient_Header + if itr.n.header.m == schema.Maybe_Absent { + v = datamodel.Absent + break } - v = itr.n.unprotected.v.Representation() + v = itr.n.header.v + case 1: + k = &fieldName__EncodedRecipient_Encrypted_key + if itr.n.encrypted_key.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.encrypted_key.v default: panic("unreachable") } itr.idx++ return } -func (itr *_JOSE__ReprMapItr) Done() bool { - return itr.idx >= itr.end +func (itr *_EncodedRecipient__MapItr) Done() bool { + return itr.idx >= 2 } -func (_JOSE__Repr) ListIterator() datamodel.ListIterator { + +func (EncodedRecipient) ListIterator() datamodel.ListIterator { return nil } -func (rn *_JOSE__Repr) Length() int64 { - l := 10 - if rn.aad.m == schema.Maybe_Absent { - l-- - } - if rn.ciphertext.m == schema.Maybe_Absent { - l-- - } - if rn.iv.m == schema.Maybe_Absent { - l-- - } - if rn.link.m == schema.Maybe_Absent { - l-- - } - if rn.payload.m == schema.Maybe_Absent { - l-- - } - if rn.protected.m == schema.Maybe_Absent { - l-- - } - if rn.recipients.m == schema.Maybe_Absent { - l-- - } - if rn.signatures.m == schema.Maybe_Absent { - l-- - } - if rn.tag.m == schema.Maybe_Absent { - l-- - } - if rn.unprotected.m == schema.Maybe_Absent { - l-- - } - return int64(l) +func (EncodedRecipient) Length() int64 { + return 2 } -func (_JOSE__Repr) IsAbsent() bool { +func (EncodedRecipient) IsAbsent() bool { return false } -func (_JOSE__Repr) IsNull() bool { +func (EncodedRecipient) IsNull() bool { return false } -func (_JOSE__Repr) AsBool() (bool, error) { - return mixins.Map{TypeName: "dagjose.JOSE.Repr"}.AsBool() +func (EncodedRecipient) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient"}.AsBool() } -func (_JOSE__Repr) AsInt() (int64, error) { - return mixins.Map{TypeName: "dagjose.JOSE.Repr"}.AsInt() +func (EncodedRecipient) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient"}.AsInt() } -func (_JOSE__Repr) AsFloat() (float64, error) { - return mixins.Map{TypeName: "dagjose.JOSE.Repr"}.AsFloat() +func (EncodedRecipient) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient"}.AsFloat() } -func (_JOSE__Repr) AsString() (string, error) { - return mixins.Map{TypeName: "dagjose.JOSE.Repr"}.AsString() +func (EncodedRecipient) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient"}.AsString() } -func (_JOSE__Repr) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "dagjose.JOSE.Repr"}.AsBytes() +func (EncodedRecipient) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient"}.AsBytes() } -func (_JOSE__Repr) AsLink() (datamodel.Link, error) { - return mixins.Map{TypeName: "dagjose.JOSE.Repr"}.AsLink() +func (EncodedRecipient) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient"}.AsLink() } -func (_JOSE__Repr) Prototype() datamodel.NodePrototype { - return _JOSE__ReprPrototype{} +func (EncodedRecipient) Prototype() datamodel.NodePrototype { + return _EncodedRecipient__Prototype{} } -type _JOSE__ReprPrototype struct{} +type _EncodedRecipient__Prototype struct{} -func (_JOSE__ReprPrototype) NewBuilder() datamodel.NodeBuilder { - var nb _JOSE__ReprBuilder +func (_EncodedRecipient__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _EncodedRecipient__Builder nb.Reset() return &nb } -type _JOSE__ReprBuilder struct { - _JOSE__ReprAssembler +type _EncodedRecipient__Builder struct { + _EncodedRecipient__Assembler } -func (nb *_JOSE__ReprBuilder) Build() datamodel.Node { +func (nb *_EncodedRecipient__Builder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_JOSE__ReprBuilder) Reset() { - var w _JOSE +func (nb *_EncodedRecipient__Builder) Reset() { + var w _EncodedRecipient var m schema.Maybe - *nb = _JOSE__ReprBuilder{_JOSE__ReprAssembler{w: &w, m: &m}} + *nb = _EncodedRecipient__Builder{_EncodedRecipient__Assembler{w: &w, m: &m}} } -type _JOSE__ReprAssembler struct { - w *_JOSE +type _EncodedRecipient__Assembler struct { + w *_EncodedRecipient m *schema.Maybe state maState s int f int - cm schema.Maybe - ca_aad _Base64Url__ReprAssembler - ca_ciphertext _Base64Url__ReprAssembler - ca_iv _Base64Url__ReprAssembler - ca_link _Link__ReprAssembler - ca_payload _Base64Url__ReprAssembler - ca_protected _Base64Url__ReprAssembler - ca_recipients _Recipients__ReprAssembler - ca_signatures _Signatures__ReprAssembler - ca_tag _Base64Url__ReprAssembler - ca_unprotected _Any__ReprAssembler + cm schema.Maybe + ca_header _Any__Assembler + ca_encrypted_key _Raw__Assembler } -func (na *_JOSE__ReprAssembler) reset() { +func (na *_EncodedRecipient__Assembler) reset() { na.state = maState_initial na.s = 0 - na.ca_aad.reset() - na.ca_ciphertext.reset() - na.ca_iv.reset() - na.ca_link.reset() - na.ca_payload.reset() - na.ca_protected.reset() - na.ca_recipients.reset() - na.ca_signatures.reset() - na.ca_tag.reset() - na.ca_unprotected.reset() + na.ca_header.reset() + na.ca_encrypted_key.reset() } -func (na *_JOSE__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, error) { + +var ( + fieldBit__EncodedRecipient_Header = 1 << 0 + fieldBit__EncodedRecipient_Encrypted_key = 1 << 1 + fieldBits__EncodedRecipient_sufficient = 0 +) + +func (na *_EncodedRecipient__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -2943,20 +8255,20 @@ func (na *_JOSE__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, error) } *na.m = midvalue if na.w == nil { - na.w = &_JOSE{} + na.w = &_EncodedRecipient{} } return na, nil } -func (_JOSE__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.MapAssembler{TypeName: "dagjose.JOSE.Repr"}.BeginList(0) +func (_EncodedRecipient__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient"}.BeginList(0) } -func (na *_JOSE__ReprAssembler) AssignNull() error { +func (na *_EncodedRecipient__Assembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{TypeName: "dagjose.JOSE.Repr.Repr"}.AssignNull() + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -2964,29 +8276,29 @@ func (na *_JOSE__ReprAssembler) AssignNull() error { } panic("unreachable") } -func (_JOSE__ReprAssembler) AssignBool(bool) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE.Repr"}.AssignBool(false) +func (_EncodedRecipient__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient"}.AssignBool(false) } -func (_JOSE__ReprAssembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE.Repr"}.AssignInt(0) +func (_EncodedRecipient__Assembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient"}.AssignInt(0) } -func (_JOSE__ReprAssembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE.Repr"}.AssignFloat(0) +func (_EncodedRecipient__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient"}.AssignFloat(0) } -func (_JOSE__ReprAssembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE.Repr"}.AssignString("") +func (_EncodedRecipient__Assembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient"}.AssignString("") } -func (_JOSE__ReprAssembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE.Repr"}.AssignBytes(nil) +func (_EncodedRecipient__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient"}.AssignBytes(nil) } -func (_JOSE__ReprAssembler) AssignLink(datamodel.Link) error { - return mixins.MapAssembler{TypeName: "dagjose.JOSE.Repr"}.AssignLink(nil) +func (_EncodedRecipient__Assembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient"}.AssignLink(nil) } -func (na *_JOSE__ReprAssembler) AssignNode(v datamodel.Node) error { +func (na *_EncodedRecipient__Assembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_JOSE); ok { + if v2, ok := v.(*_EncodedRecipient); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -3003,7 +8315,7 @@ func (na *_JOSE__ReprAssembler) AssignNode(v datamodel.Node) error { return nil } if v.Kind() != datamodel.Kind_Map { - return datamodel.ErrWrongKind{TypeName: "dagjose.JOSE.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + return datamodel.ErrWrongKind{TypeName: "dagjose.EncodedRecipient", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} } itr := v.MapIterator() for !itr.Done() { @@ -3020,227 +8332,72 @@ func (na *_JOSE__ReprAssembler) AssignNode(v datamodel.Node) error { } return na.Finish() } -func (_JOSE__ReprAssembler) Prototype() datamodel.NodePrototype { - return _JOSE__ReprPrototype{} +func (_EncodedRecipient__Assembler) Prototype() datamodel.NodePrototype { + return _EncodedRecipient__Prototype{} } -func (ma *_JOSE__ReprAssembler) valueFinishTidy() bool { +func (ma *_EncodedRecipient__Assembler) valueFinishTidy() bool { switch ma.f { case 0: - switch ma.w.aad.m { + switch ma.w.header.m { case schema.Maybe_Value: + ma.w.header.v = ma.ca_header.w ma.state = maState_initial return true default: return false } case 1: - switch ma.w.ciphertext.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 2: - switch ma.w.iv.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 3: - switch ma.w.link.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 4: - switch ma.w.payload.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 5: - switch ma.w.protected.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 6: - switch ma.w.recipients.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 7: - switch ma.w.signatures.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 8: - switch ma.w.tag.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 9: - switch ma.w.unprotected.m { + switch ma.w.encrypted_key.m { case schema.Maybe_Value: - ma.w.unprotected.v = ma.ca_unprotected.w ma.state = maState_initial return true default: return false } default: - panic("unreachable") - } -} -func (ma *_JOSE__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { - switch ma.state { - case maState_initial: - // carry on - case maState_midKey: - panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") - case maState_expectValue: - panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") - } // if tidy success: carry on - case maState_finished: - panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") - } - switch k { - case "aad": - if ma.s&fieldBit__JOSE_Aad != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Aad_serial} - } - ma.s += fieldBit__JOSE_Aad - ma.state = maState_midValue - ma.f = 0 - ma.ca_aad.w = &ma.w.aad.v - ma.ca_aad.m = &ma.w.aad.m - - return &ma.ca_aad, nil - case "ciphertext": - if ma.s&fieldBit__JOSE_Ciphertext != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Ciphertext_serial} - } - ma.s += fieldBit__JOSE_Ciphertext - ma.state = maState_midValue - ma.f = 1 - ma.ca_ciphertext.w = &ma.w.ciphertext.v - ma.ca_ciphertext.m = &ma.w.ciphertext.m - - return &ma.ca_ciphertext, nil - case "iv": - if ma.s&fieldBit__JOSE_Iv != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Iv_serial} - } - ma.s += fieldBit__JOSE_Iv - ma.state = maState_midValue - ma.f = 2 - ma.ca_iv.w = &ma.w.iv.v - ma.ca_iv.m = &ma.w.iv.m - - return &ma.ca_iv, nil - case "link": - if ma.s&fieldBit__JOSE_Link != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Link_serial} - } - ma.s += fieldBit__JOSE_Link - ma.state = maState_midValue - ma.f = 3 - ma.ca_link.w = &ma.w.link.v - ma.ca_link.m = &ma.w.link.m - - return &ma.ca_link, nil - case "payload": - if ma.s&fieldBit__JOSE_Payload != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Payload_serial} - } - ma.s += fieldBit__JOSE_Payload - ma.state = maState_midValue - ma.f = 4 - ma.ca_payload.w = &ma.w.payload.v - ma.ca_payload.m = &ma.w.payload.m - - return &ma.ca_payload, nil - case "protected": - if ma.s&fieldBit__JOSE_Protected != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Protected_serial} - } - ma.s += fieldBit__JOSE_Protected - ma.state = maState_midValue - ma.f = 5 - ma.ca_protected.w = &ma.w.protected.v - ma.ca_protected.m = &ma.w.protected.m - - return &ma.ca_protected, nil - case "recipients": - if ma.s&fieldBit__JOSE_Recipients != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Recipients_serial} - } - ma.s += fieldBit__JOSE_Recipients - ma.state = maState_midValue - ma.f = 6 - ma.ca_recipients.w = &ma.w.recipients.v - ma.ca_recipients.m = &ma.w.recipients.m - - return &ma.ca_recipients, nil - case "signatures": - if ma.s&fieldBit__JOSE_Signatures != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Signatures_serial} - } - ma.s += fieldBit__JOSE_Signatures - ma.state = maState_midValue - ma.f = 7 - ma.ca_signatures.w = &ma.w.signatures.v - ma.ca_signatures.m = &ma.w.signatures.m - - return &ma.ca_signatures, nil - case "tag": - if ma.s&fieldBit__JOSE_Tag != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Tag_serial} + panic("unreachable") + } +} +func (ma *_EncodedRecipient__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "header": + if ma.s&fieldBit__EncodedRecipient_Header != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedRecipient_Header} } - ma.s += fieldBit__JOSE_Tag + ma.s += fieldBit__EncodedRecipient_Header ma.state = maState_midValue - ma.f = 8 - ma.ca_tag.w = &ma.w.tag.v - ma.ca_tag.m = &ma.w.tag.m - - return &ma.ca_tag, nil - case "unprotected": - if ma.s&fieldBit__JOSE_Unprotected != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Unprotected_serial} + ma.f = 0 + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + return &ma.ca_header, nil + case "encrypted_key": + if ma.s&fieldBit__EncodedRecipient_Encrypted_key != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedRecipient_Encrypted_key} } - ma.s += fieldBit__JOSE_Unprotected + ma.s += fieldBit__EncodedRecipient_Encrypted_key ma.state = maState_midValue - ma.f = 9 - ma.ca_unprotected.w = ma.w.unprotected.v - ma.ca_unprotected.m = &ma.w.unprotected.m - - return &ma.ca_unprotected, nil - default: + ma.f = 1 + ma.ca_encrypted_key.w = &ma.w.encrypted_key.v + ma.ca_encrypted_key.m = &ma.w.encrypted_key.m + return &ma.ca_encrypted_key, nil } - return nil, schema.ErrInvalidKey{TypeName: "dagjose.JOSE.Repr", Key: &_String{k}} + return nil, schema.ErrInvalidKey{TypeName: "dagjose.EncodedRecipient", Key: &_String{k}} } -func (ma *_JOSE__ReprAssembler) AssembleKey() datamodel.NodeAssembler { +func (ma *_EncodedRecipient__Assembler) AssembleKey() datamodel.NodeAssembler { switch ma.state { case maState_initial: // carry on @@ -3256,9 +8413,9 @@ func (ma *_JOSE__ReprAssembler) AssembleKey() datamodel.NodeAssembler { panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") } ma.state = maState_midKey - return (*_JOSE__ReprKeyAssembler)(ma) + return (*_EncodedRecipient__KeyAssembler)(ma) } -func (ma *_JOSE__ReprAssembler) AssembleValue() datamodel.NodeAssembler { +func (ma *_EncodedRecipient__Assembler) AssembleValue() datamodel.NodeAssembler { switch ma.state { case maState_initial: panic("invalid state: AssembleValue cannot be called when no key is primed") @@ -3274,60 +8431,18 @@ func (ma *_JOSE__ReprAssembler) AssembleValue() datamodel.NodeAssembler { ma.state = maState_midValue switch ma.f { case 0: - ma.ca_aad.w = &ma.w.aad.v - ma.ca_aad.m = &ma.w.aad.m - - return &ma.ca_aad + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + return &ma.ca_header case 1: - ma.ca_ciphertext.w = &ma.w.ciphertext.v - ma.ca_ciphertext.m = &ma.w.ciphertext.m - - return &ma.ca_ciphertext - case 2: - ma.ca_iv.w = &ma.w.iv.v - ma.ca_iv.m = &ma.w.iv.m - - return &ma.ca_iv - case 3: - ma.ca_link.w = &ma.w.link.v - ma.ca_link.m = &ma.w.link.m - - return &ma.ca_link - case 4: - ma.ca_payload.w = &ma.w.payload.v - ma.ca_payload.m = &ma.w.payload.m - - return &ma.ca_payload - case 5: - ma.ca_protected.w = &ma.w.protected.v - ma.ca_protected.m = &ma.w.protected.m - - return &ma.ca_protected - case 6: - ma.ca_recipients.w = &ma.w.recipients.v - ma.ca_recipients.m = &ma.w.recipients.m - - return &ma.ca_recipients - case 7: - ma.ca_signatures.w = &ma.w.signatures.v - ma.ca_signatures.m = &ma.w.signatures.m - - return &ma.ca_signatures - case 8: - ma.ca_tag.w = &ma.w.tag.v - ma.ca_tag.m = &ma.w.tag.m - - return &ma.ca_tag - case 9: - ma.ca_unprotected.w = ma.w.unprotected.v - ma.ca_unprotected.m = &ma.w.unprotected.m - - return &ma.ca_unprotected + ma.ca_encrypted_key.w = &ma.w.encrypted_key.v + ma.ca_encrypted_key.m = &ma.w.encrypted_key.m + return &ma.ca_encrypted_key default: panic("unreachable") } } -func (ma *_JOSE__ReprAssembler) Finish() error { +func (ma *_EncodedRecipient__Assembler) Finish() error { switch ma.state { case maState_initial: // carry on @@ -3342,7 +8457,7 @@ func (ma *_JOSE__ReprAssembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s&fieldBits__JOSE_sufficient != fieldBits__JOSE_sufficient { + if ma.s&fieldBits__EncodedRecipient_sufficient != fieldBits__EncodedRecipient_sufficient { err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} return err } @@ -3350,373 +8465,577 @@ func (ma *_JOSE__ReprAssembler) Finish() error { *ma.m = schema.Maybe_Value return nil } -func (ma *_JOSE__ReprAssembler) KeyPrototype() datamodel.NodePrototype { +func (ma *_EncodedRecipient__Assembler) KeyPrototype() datamodel.NodePrototype { return _String__Prototype{} } -func (ma *_JOSE__ReprAssembler) ValuePrototype(k string) datamodel.NodePrototype { - panic("todo structbuilder mapassembler repr valueprototype") +func (ma *_EncodedRecipient__Assembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler valueprototype") } -type _JOSE__ReprKeyAssembler _JOSE__ReprAssembler +type _EncodedRecipient__KeyAssembler _EncodedRecipient__Assembler -func (_JOSE__ReprKeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.Repr.KeyAssembler"}.BeginMap(0) +func (_EncodedRecipient__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.KeyAssembler"}.BeginMap(0) } -func (_JOSE__ReprKeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.Repr.KeyAssembler"}.BeginList(0) +func (_EncodedRecipient__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.KeyAssembler"}.BeginList(0) } -func (na *_JOSE__ReprKeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.Repr.KeyAssembler"}.AssignNull() +func (na *_EncodedRecipient__KeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.KeyAssembler"}.AssignNull() } -func (_JOSE__ReprKeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.Repr.KeyAssembler"}.AssignBool(false) +func (_EncodedRecipient__KeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.KeyAssembler"}.AssignBool(false) } -func (_JOSE__ReprKeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.Repr.KeyAssembler"}.AssignInt(0) +func (_EncodedRecipient__KeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.KeyAssembler"}.AssignInt(0) } -func (_JOSE__ReprKeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.Repr.KeyAssembler"}.AssignFloat(0) +func (_EncodedRecipient__KeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.KeyAssembler"}.AssignFloat(0) } -func (ka *_JOSE__ReprKeyAssembler) AssignString(k string) error { +func (ka *_EncodedRecipient__KeyAssembler) AssignString(k string) error { if ka.state != maState_midKey { panic("misuse: KeyAssembler held beyond its valid lifetime") } switch k { - case "aad": - if ka.s&fieldBit__JOSE_Aad != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Aad_serial} + case "header": + if ka.s&fieldBit__EncodedRecipient_Header != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedRecipient_Header} } - ka.s += fieldBit__JOSE_Aad + ka.s += fieldBit__EncodedRecipient_Header ka.state = maState_expectValue ka.f = 0 return nil - case "ciphertext": - if ka.s&fieldBit__JOSE_Ciphertext != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Ciphertext_serial} + case "encrypted_key": + if ka.s&fieldBit__EncodedRecipient_Encrypted_key != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedRecipient_Encrypted_key} } - ka.s += fieldBit__JOSE_Ciphertext + ka.s += fieldBit__EncodedRecipient_Encrypted_key ka.state = maState_expectValue ka.f = 1 return nil - case "iv": - if ka.s&fieldBit__JOSE_Iv != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Iv_serial} - } - ka.s += fieldBit__JOSE_Iv - ka.state = maState_expectValue - ka.f = 2 - return nil - case "link": - if ka.s&fieldBit__JOSE_Link != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Link_serial} - } - ka.s += fieldBit__JOSE_Link - ka.state = maState_expectValue - ka.f = 3 - return nil - case "payload": - if ka.s&fieldBit__JOSE_Payload != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Payload_serial} - } - ka.s += fieldBit__JOSE_Payload - ka.state = maState_expectValue - ka.f = 4 - return nil - case "protected": - if ka.s&fieldBit__JOSE_Protected != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Protected_serial} - } - ka.s += fieldBit__JOSE_Protected - ka.state = maState_expectValue - ka.f = 5 - return nil - case "recipients": - if ka.s&fieldBit__JOSE_Recipients != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Recipients_serial} - } - ka.s += fieldBit__JOSE_Recipients - ka.state = maState_expectValue - ka.f = 6 - return nil - case "signatures": - if ka.s&fieldBit__JOSE_Signatures != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Signatures_serial} - } - ka.s += fieldBit__JOSE_Signatures - ka.state = maState_expectValue - ka.f = 7 - return nil - case "tag": - if ka.s&fieldBit__JOSE_Tag != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Tag_serial} - } - ka.s += fieldBit__JOSE_Tag - ka.state = maState_expectValue - ka.f = 8 - return nil - case "unprotected": - if ka.s&fieldBit__JOSE_Unprotected != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__JOSE_Unprotected_serial} - } - ka.s += fieldBit__JOSE_Unprotected - ka.state = maState_expectValue - ka.f = 9 - return nil + default: + return schema.ErrInvalidKey{TypeName: "dagjose.EncodedRecipient", Key: &_String{k}} } - return schema.ErrInvalidKey{TypeName: "dagjose.JOSE.Repr", Key: &_String{k}} } -func (_JOSE__ReprKeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.Repr.KeyAssembler"}.AssignBytes(nil) +func (_EncodedRecipient__KeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.KeyAssembler"}.AssignBytes(nil) } -func (_JOSE__ReprKeyAssembler) AssignLink(datamodel.Link) error { - return mixins.StringAssembler{TypeName: "dagjose.JOSE.Repr.KeyAssembler"}.AssignLink(nil) +func (_EncodedRecipient__KeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.KeyAssembler"}.AssignLink(nil) } -func (ka *_JOSE__ReprKeyAssembler) AssignNode(v datamodel.Node) error { +func (ka *_EncodedRecipient__KeyAssembler) AssignNode(v datamodel.Node) error { if v2, err := v.AsString(); err != nil { return err } else { return ka.AssignString(v2) } } -func (_JOSE__ReprKeyAssembler) Prototype() datamodel.NodePrototype { +func (_EncodedRecipient__KeyAssembler) Prototype() datamodel.NodePrototype { return _String__Prototype{} } - -func (n Link) Link() datamodel.Link { - return n.x +func (EncodedRecipient) Type() schema.Type { + return nil /*TODO:typelit*/ } -func (_Link__Prototype) FromLink(v datamodel.Link) (Link, error) { - n := _Link{v} - return &n, nil +func (n EncodedRecipient) Representation() datamodel.Node { + return (*_EncodedRecipient__Repr)(n) } -type _Link__Maybe struct { - m schema.Maybe - v _Link -} -type MaybeLink = *_Link__Maybe +type _EncodedRecipient__Repr _EncodedRecipient -func (m MaybeLink) IsNull() bool { - return m.m == schema.Maybe_Null -} -func (m MaybeLink) IsAbsent() bool { - return m.m == schema.Maybe_Absent -} -func (m MaybeLink) Exists() bool { - return m.m == schema.Maybe_Value +var ( + fieldName__EncodedRecipient_Header_serial = _String{"header"} + fieldName__EncodedRecipient_Encrypted_key_serial = _String{"encrypted_key"} +) +var _ datamodel.Node = &_EncodedRecipient__Repr{} + +func (_EncodedRecipient__Repr) Kind() datamodel.Kind { + return datamodel.Kind_Map } -func (m MaybeLink) AsNode() datamodel.Node { - switch m.m { - case schema.Maybe_Absent: - return datamodel.Absent - case schema.Maybe_Null: - return datamodel.Null - case schema.Maybe_Value: - return &m.v +func (n *_EncodedRecipient__Repr) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "header": + if n.header.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.header.v.Representation(), nil + case "encrypted_key": + if n.encrypted_key.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.encrypted_key.v.Representation(), nil default: - panic("unreachable") + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} } } -func (m MaybeLink) Must() Link { - if !m.Exists() { - panic("unbox of a maybe rejected") +func (n *_EncodedRecipient__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err } - return &m.v + return n.LookupByString(ks) } - -var _ datamodel.Node = (Link)(&_Link{}) -var _ schema.TypedNode = (Link)(&_Link{}) - -func (Link) Kind() datamodel.Kind { - return datamodel.Kind_Link +func (_EncodedRecipient__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient.Repr"}.LookupByIndex(0) } -func (Link) LookupByString(string) (datamodel.Node, error) { - return mixins.Link{TypeName: "dagjose.Link"}.LookupByString("") +func (n _EncodedRecipient__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) } -func (Link) LookupByNode(datamodel.Node) (datamodel.Node, error) { - return mixins.Link{TypeName: "dagjose.Link"}.LookupByNode(nil) +func (n *_EncodedRecipient__Repr) MapIterator() datamodel.MapIterator { + end := 2 + if n.encrypted_key.m == schema.Maybe_Absent { + end = 1 + } else { + goto done + } + if n.header.m == schema.Maybe_Absent { + end = 0 + } else { + goto done + } +done: + return &_EncodedRecipient__ReprMapItr{n, 0, end} } -func (Link) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Link{TypeName: "dagjose.Link"}.LookupByIndex(0) + +type _EncodedRecipient__ReprMapItr struct { + n *_EncodedRecipient__Repr + idx int + end int } -func (Link) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - return mixins.Link{TypeName: "dagjose.Link"}.LookupBySegment(seg) + +func (itr *_EncodedRecipient__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { +advance: + if itr.idx >= 2 { + return nil, nil, datamodel.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__EncodedRecipient_Header_serial + if itr.n.header.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.header.v.Representation() + case 1: + k = &fieldName__EncodedRecipient_Encrypted_key_serial + if itr.n.encrypted_key.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.encrypted_key.v.Representation() + default: + panic("unreachable") + } + itr.idx++ + return } -func (Link) MapIterator() datamodel.MapIterator { - return nil +func (itr *_EncodedRecipient__ReprMapItr) Done() bool { + return itr.idx >= itr.end } -func (Link) ListIterator() datamodel.ListIterator { +func (_EncodedRecipient__Repr) ListIterator() datamodel.ListIterator { return nil } -func (Link) Length() int64 { - return -1 +func (rn *_EncodedRecipient__Repr) Length() int64 { + l := 2 + if rn.header.m == schema.Maybe_Absent { + l-- + } + if rn.encrypted_key.m == schema.Maybe_Absent { + l-- + } + return int64(l) } -func (Link) IsAbsent() bool { +func (_EncodedRecipient__Repr) IsAbsent() bool { return false } -func (Link) IsNull() bool { +func (_EncodedRecipient__Repr) IsNull() bool { return false } -func (Link) AsBool() (bool, error) { - return mixins.Link{TypeName: "dagjose.Link"}.AsBool() +func (_EncodedRecipient__Repr) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient.Repr"}.AsBool() } -func (Link) AsInt() (int64, error) { - return mixins.Link{TypeName: "dagjose.Link"}.AsInt() +func (_EncodedRecipient__Repr) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient.Repr"}.AsInt() } -func (Link) AsFloat() (float64, error) { - return mixins.Link{TypeName: "dagjose.Link"}.AsFloat() +func (_EncodedRecipient__Repr) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient.Repr"}.AsFloat() } -func (Link) AsString() (string, error) { - return mixins.Link{TypeName: "dagjose.Link"}.AsString() +func (_EncodedRecipient__Repr) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient.Repr"}.AsString() } -func (Link) AsBytes() ([]byte, error) { - return mixins.Link{TypeName: "dagjose.Link"}.AsBytes() +func (_EncodedRecipient__Repr) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient.Repr"}.AsBytes() } -func (n Link) AsLink() (datamodel.Link, error) { - return n.x, nil +func (_EncodedRecipient__Repr) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.EncodedRecipient.Repr"}.AsLink() } -func (Link) Prototype() datamodel.NodePrototype { - return _Link__Prototype{} +func (_EncodedRecipient__Repr) Prototype() datamodel.NodePrototype { + return _EncodedRecipient__ReprPrototype{} } -type _Link__Prototype struct{} +type _EncodedRecipient__ReprPrototype struct{} -func (_Link__Prototype) NewBuilder() datamodel.NodeBuilder { - var nb _Link__Builder +func (_EncodedRecipient__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _EncodedRecipient__ReprBuilder nb.Reset() return &nb } -type _Link__Builder struct { - _Link__Assembler +type _EncodedRecipient__ReprBuilder struct { + _EncodedRecipient__ReprAssembler } -func (nb *_Link__Builder) Build() datamodel.Node { +func (nb *_EncodedRecipient__ReprBuilder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Link__Builder) Reset() { - var w _Link +func (nb *_EncodedRecipient__ReprBuilder) Reset() { + var w _EncodedRecipient var m schema.Maybe - *nb = _Link__Builder{_Link__Assembler{w: &w, m: &m}} + *nb = _EncodedRecipient__ReprBuilder{_EncodedRecipient__ReprAssembler{w: &w, m: &m}} } -type _Link__Assembler struct { - w *_Link - m *schema.Maybe +type _EncodedRecipient__ReprAssembler struct { + w *_EncodedRecipient + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_header _Any__ReprAssembler + ca_encrypted_key _Raw__ReprAssembler } -func (na *_Link__Assembler) reset() {} -func (_Link__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.LinkAssembler{TypeName: "dagjose.Link"}.BeginMap(0) +func (na *_EncodedRecipient__ReprAssembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_header.reset() + na.ca_encrypted_key.reset() } -func (_Link__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.LinkAssembler{TypeName: "dagjose.Link"}.BeginList(0) +func (na *_EncodedRecipient__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_EncodedRecipient{} + } + return na, nil } -func (na *_Link__Assembler) AssignNull() error { +func (_EncodedRecipient__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient.Repr"}.BeginList(0) +} +func (na *_EncodedRecipient__ReprAssembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignNull() + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } panic("unreachable") } -func (_Link__Assembler) AssignBool(bool) error { - return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignBool(false) +func (_EncodedRecipient__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient.Repr"}.AssignBool(false) } -func (_Link__Assembler) AssignInt(int64) error { - return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignInt(0) +func (_EncodedRecipient__ReprAssembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient.Repr"}.AssignInt(0) } -func (_Link__Assembler) AssignFloat(float64) error { - return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignFloat(0) +func (_EncodedRecipient__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient.Repr"}.AssignFloat(0) } -func (_Link__Assembler) AssignString(string) error { - return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignString("") +func (_EncodedRecipient__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient.Repr"}.AssignString("") } -func (_Link__Assembler) AssignBytes([]byte) error { - return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignBytes(nil) +func (_EncodedRecipient__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient.Repr"}.AssignBytes(nil) } -func (na *_Link__Assembler) AssignLink(v datamodel.Link) error { - switch *na.m { - case schema.Maybe_Value, schema.Maybe_Null: - panic("invalid state: cannot assign into assembler that's already finished") - } - na.w.x = v - *na.m = schema.Maybe_Value - return nil +func (_EncodedRecipient__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedRecipient.Repr"}.AssignLink(nil) } -func (na *_Link__Assembler) AssignNode(v datamodel.Node) error { +func (na *_EncodedRecipient__ReprAssembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Link); ok { + if v2, ok := v.(*_EncodedRecipient); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil } *na.w = *v2 *na.m = schema.Maybe_Value return nil } - if v2, err := v.AsLink(); err != nil { + if v.Kind() != datamodel.Kind_Map { + return datamodel.ErrWrongKind{TypeName: "dagjose.EncodedRecipient.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_EncodedRecipient__ReprAssembler) Prototype() datamodel.NodePrototype { + return _EncodedRecipient__ReprPrototype{} +} +func (ma *_EncodedRecipient__ReprAssembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.header.m { + case schema.Maybe_Value: + ma.w.header.v = ma.ca_header.w + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.encrypted_key.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_EncodedRecipient__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "header": + if ma.s&fieldBit__EncodedRecipient_Header != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedRecipient_Header_serial} + } + ma.s += fieldBit__EncodedRecipient_Header + ma.state = maState_midValue + ma.f = 0 + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + + return &ma.ca_header, nil + case "encrypted_key": + if ma.s&fieldBit__EncodedRecipient_Encrypted_key != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedRecipient_Encrypted_key_serial} + } + ma.s += fieldBit__EncodedRecipient_Encrypted_key + ma.state = maState_midValue + ma.f = 1 + ma.ca_encrypted_key.w = &ma.w.encrypted_key.v + ma.ca_encrypted_key.m = &ma.w.encrypted_key.m + + return &ma.ca_encrypted_key, nil + default: + } + return nil, schema.ErrInvalidKey{TypeName: "dagjose.EncodedRecipient.Repr", Key: &_String{k}} +} +func (ma *_EncodedRecipient__ReprAssembler) AssembleKey() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_EncodedRecipient__ReprKeyAssembler)(ma) +} +func (ma *_EncodedRecipient__ReprAssembler) AssembleValue() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + + return &ma.ca_header + case 1: + ma.ca_encrypted_key.w = &ma.w.encrypted_key.v + ma.ca_encrypted_key.m = &ma.w.encrypted_key.m + + return &ma.ca_encrypted_key + default: + panic("unreachable") + } +} +func (ma *_EncodedRecipient__ReprAssembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__EncodedRecipient_sufficient != fieldBits__EncodedRecipient_sufficient { + err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} return err - } else { - return na.AssignLink(v2) } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_EncodedRecipient__ReprAssembler) KeyPrototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (ma *_EncodedRecipient__ReprAssembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler repr valueprototype") +} + +type _EncodedRecipient__ReprKeyAssembler _EncodedRecipient__ReprAssembler + +func (_EncodedRecipient__ReprKeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.Repr.KeyAssembler"}.BeginMap(0) +} +func (_EncodedRecipient__ReprKeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.Repr.KeyAssembler"}.BeginList(0) +} +func (na *_EncodedRecipient__ReprKeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.Repr.KeyAssembler"}.AssignNull() +} +func (_EncodedRecipient__ReprKeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.Repr.KeyAssembler"}.AssignBool(false) +} +func (_EncodedRecipient__ReprKeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.Repr.KeyAssembler"}.AssignInt(0) +} +func (_EncodedRecipient__ReprKeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.Repr.KeyAssembler"}.AssignFloat(0) +} +func (ka *_EncodedRecipient__ReprKeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "header": + if ka.s&fieldBit__EncodedRecipient_Header != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedRecipient_Header_serial} + } + ka.s += fieldBit__EncodedRecipient_Header + ka.state = maState_expectValue + ka.f = 0 + return nil + case "encrypted_key": + if ka.s&fieldBit__EncodedRecipient_Encrypted_key != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedRecipient_Encrypted_key_serial} + } + ka.s += fieldBit__EncodedRecipient_Encrypted_key + ka.state = maState_expectValue + ka.f = 1 + return nil + } + return schema.ErrInvalidKey{TypeName: "dagjose.EncodedRecipient.Repr", Key: &_String{k}} } -func (_Link__Assembler) Prototype() datamodel.NodePrototype { - return _Link__Prototype{} +func (_EncodedRecipient__ReprKeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.Repr.KeyAssembler"}.AssignBytes(nil) } -func (Link) Type() schema.Type { - return nil /*TODO:typelit*/ +func (_EncodedRecipient__ReprKeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedRecipient.Repr.KeyAssembler"}.AssignLink(nil) } -func (n Link) Representation() datamodel.Node { - return (*_Link__Repr)(n) +func (ka *_EncodedRecipient__ReprKeyAssembler) AssignNode(v datamodel.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_EncodedRecipient__ReprKeyAssembler) Prototype() datamodel.NodePrototype { + return _String__Prototype{} } -type _Link__Repr = _Link - -var _ datamodel.Node = &_Link__Repr{} - -type _Link__ReprPrototype = _Link__Prototype -type _Link__ReprAssembler = _Link__Assembler - -func (n *_List) Lookup(idx int64) Any { +func (n *_EncodedRecipients) Lookup(idx int64) EncodedRecipient { if n.Length() <= idx { return nil } v := &n.x[idx] return v } -func (n *_List) LookupMaybe(idx int64) MaybeAny { +func (n *_EncodedRecipients) LookupMaybe(idx int64) MaybeEncodedRecipient { if n.Length() <= idx { return nil } v := &n.x[idx] - return &_Any__Maybe{ + return &_EncodedRecipient__Maybe{ m: schema.Maybe_Value, v: v, } } -var _List__valueAbsent = _Any__Maybe{m: schema.Maybe_Absent} +var _EncodedRecipients__valueAbsent = _EncodedRecipient__Maybe{m: schema.Maybe_Absent} -func (n List) Iterator() *List__Itr { - return &List__Itr{n, 0} +func (n EncodedRecipients) Iterator() *EncodedRecipients__Itr { + return &EncodedRecipients__Itr{n, 0} } -type List__Itr struct { - n List +type EncodedRecipients__Itr struct { + n EncodedRecipients idx int } -func (itr *List__Itr) Next() (idx int64, v Any) { +func (itr *EncodedRecipients__Itr) Next() (idx int64, v EncodedRecipient) { if itr.idx >= len(itr.n.x) { return -1, nil } @@ -3725,26 +9044,26 @@ func (itr *List__Itr) Next() (idx int64, v Any) { itr.idx++ return } -func (itr *List__Itr) Done() bool { +func (itr *EncodedRecipients__Itr) Done() bool { return itr.idx >= len(itr.n.x) } -type _List__Maybe struct { +type _EncodedRecipients__Maybe struct { m schema.Maybe - v _List + v _EncodedRecipients } -type MaybeList = *_List__Maybe +type MaybeEncodedRecipients = *_EncodedRecipients__Maybe -func (m MaybeList) IsNull() bool { +func (m MaybeEncodedRecipients) IsNull() bool { return m.m == schema.Maybe_Null } -func (m MaybeList) IsAbsent() bool { +func (m MaybeEncodedRecipients) IsAbsent() bool { return m.m == schema.Maybe_Absent } -func (m MaybeList) Exists() bool { +func (m MaybeEncodedRecipients) Exists() bool { return m.m == schema.Maybe_Value } -func (m MaybeList) AsNode() datamodel.Node { +func (m MaybeEncodedRecipients) AsNode() datamodel.Node { switch m.m { case schema.Maybe_Absent: return datamodel.Absent @@ -3756,56 +9075,56 @@ func (m MaybeList) AsNode() datamodel.Node { panic("unreachable") } } -func (m MaybeList) Must() List { +func (m MaybeEncodedRecipients) Must() EncodedRecipients { if !m.Exists() { panic("unbox of a maybe rejected") } return &m.v } -var _ datamodel.Node = (List)(&_List{}) -var _ schema.TypedNode = (List)(&_List{}) +var _ datamodel.Node = (EncodedRecipients)(&_EncodedRecipients{}) +var _ schema.TypedNode = (EncodedRecipients)(&_EncodedRecipients{}) -func (List) Kind() datamodel.Kind { +func (EncodedRecipients) Kind() datamodel.Kind { return datamodel.Kind_List } -func (List) LookupByString(string) (datamodel.Node, error) { - return mixins.List{TypeName: "dagjose.List"}.LookupByString("") +func (EncodedRecipients) LookupByString(string) (datamodel.Node, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients"}.LookupByString("") } -func (n List) LookupByNode(k datamodel.Node) (datamodel.Node, error) { +func (n EncodedRecipients) LookupByNode(k datamodel.Node) (datamodel.Node, error) { idx, err := k.AsInt() if err != nil { return nil, err } return n.LookupByIndex(idx) } -func (n List) LookupByIndex(idx int64) (datamodel.Node, error) { +func (n EncodedRecipients) LookupByIndex(idx int64) (datamodel.Node, error) { if n.Length() <= idx { return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)} } v := &n.x[idx] return v, nil } -func (n List) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { +func (n EncodedRecipients) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { i, err := seg.Index() if err != nil { - return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.List", TroubleSegment: seg, Reason: err} + return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.EncodedRecipients", TroubleSegment: seg, Reason: err} } return n.LookupByIndex(i) } -func (List) MapIterator() datamodel.MapIterator { +func (EncodedRecipients) MapIterator() datamodel.MapIterator { return nil } -func (n List) ListIterator() datamodel.ListIterator { - return &_List__ListItr{n, 0} +func (n EncodedRecipients) ListIterator() datamodel.ListIterator { + return &_EncodedRecipients__ListItr{n, 0} } -type _List__ListItr struct { - n List +type _EncodedRecipients__ListItr struct { + n EncodedRecipients idx int } -func (itr *_List__ListItr) Next() (idx int64, v datamodel.Node, _ error) { +func (itr *_EncodedRecipients__ListItr) Next() (idx int64, v datamodel.Node, _ error) { if itr.idx >= len(itr.n.x) { return -1, nil, datamodel.ErrIteratorOverread{} } @@ -3815,82 +9134,82 @@ func (itr *_List__ListItr) Next() (idx int64, v datamodel.Node, _ error) { itr.idx++ return } -func (itr *_List__ListItr) Done() bool { +func (itr *_EncodedRecipients__ListItr) Done() bool { return itr.idx >= len(itr.n.x) } -func (n List) Length() int64 { +func (n EncodedRecipients) Length() int64 { return int64(len(n.x)) } -func (List) IsAbsent() bool { +func (EncodedRecipients) IsAbsent() bool { return false } -func (List) IsNull() bool { +func (EncodedRecipients) IsNull() bool { return false } -func (List) AsBool() (bool, error) { - return mixins.List{TypeName: "dagjose.List"}.AsBool() +func (EncodedRecipients) AsBool() (bool, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients"}.AsBool() } -func (List) AsInt() (int64, error) { - return mixins.List{TypeName: "dagjose.List"}.AsInt() +func (EncodedRecipients) AsInt() (int64, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients"}.AsInt() } -func (List) AsFloat() (float64, error) { - return mixins.List{TypeName: "dagjose.List"}.AsFloat() +func (EncodedRecipients) AsFloat() (float64, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients"}.AsFloat() } -func (List) AsString() (string, error) { - return mixins.List{TypeName: "dagjose.List"}.AsString() +func (EncodedRecipients) AsString() (string, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients"}.AsString() } -func (List) AsBytes() ([]byte, error) { - return mixins.List{TypeName: "dagjose.List"}.AsBytes() +func (EncodedRecipients) AsBytes() ([]byte, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients"}.AsBytes() } -func (List) AsLink() (datamodel.Link, error) { - return mixins.List{TypeName: "dagjose.List"}.AsLink() +func (EncodedRecipients) AsLink() (datamodel.Link, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients"}.AsLink() } -func (List) Prototype() datamodel.NodePrototype { - return _List__Prototype{} +func (EncodedRecipients) Prototype() datamodel.NodePrototype { + return _EncodedRecipients__Prototype{} } -type _List__Prototype struct{} +type _EncodedRecipients__Prototype struct{} -func (_List__Prototype) NewBuilder() datamodel.NodeBuilder { - var nb _List__Builder +func (_EncodedRecipients__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _EncodedRecipients__Builder nb.Reset() return &nb } -type _List__Builder struct { - _List__Assembler +type _EncodedRecipients__Builder struct { + _EncodedRecipients__Assembler } -func (nb *_List__Builder) Build() datamodel.Node { +func (nb *_EncodedRecipients__Builder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_List__Builder) Reset() { - var w _List +func (nb *_EncodedRecipients__Builder) Reset() { + var w _EncodedRecipients var m schema.Maybe - *nb = _List__Builder{_List__Assembler{w: &w, m: &m}} + *nb = _EncodedRecipients__Builder{_EncodedRecipients__Assembler{w: &w, m: &m}} } -type _List__Assembler struct { - w *_List +type _EncodedRecipients__Assembler struct { + w *_EncodedRecipients m *schema.Maybe state laState cm schema.Maybe - va _Any__Assembler + va _EncodedRecipient__Assembler } -func (na *_List__Assembler) reset() { +func (na *_EncodedRecipients__Assembler) reset() { na.state = laState_initial na.va.reset() } -func (_List__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.ListAssembler{TypeName: "dagjose.List"}.BeginMap(0) +func (_EncodedRecipients__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients"}.BeginMap(0) } -func (na *_List__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { +func (na *_EncodedRecipients__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -3902,17 +9221,17 @@ func (na *_List__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, sizeHint = 0 } if sizeHint > 0 { - na.w.x = make([]_Any, 0, sizeHint) + na.w.x = make([]_EncodedRecipient, 0, sizeHint) } return na, nil } -func (na *_List__Assembler) AssignNull() error { +func (na *_EncodedRecipients__Assembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignNull() + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -3920,29 +9239,29 @@ func (na *_List__Assembler) AssignNull() error { } panic("unreachable") } -func (_List__Assembler) AssignBool(bool) error { - return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignBool(false) +func (_EncodedRecipients__Assembler) AssignBool(bool) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients"}.AssignBool(false) } -func (_List__Assembler) AssignInt(int64) error { - return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignInt(0) +func (_EncodedRecipients__Assembler) AssignInt(int64) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients"}.AssignInt(0) } -func (_List__Assembler) AssignFloat(float64) error { - return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignFloat(0) +func (_EncodedRecipients__Assembler) AssignFloat(float64) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients"}.AssignFloat(0) } -func (_List__Assembler) AssignString(string) error { - return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignString("") +func (_EncodedRecipients__Assembler) AssignString(string) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients"}.AssignString("") } -func (_List__Assembler) AssignBytes([]byte) error { - return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignBytes(nil) +func (_EncodedRecipients__Assembler) AssignBytes([]byte) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients"}.AssignBytes(nil) } -func (_List__Assembler) AssignLink(datamodel.Link) error { - return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignLink(nil) +func (_EncodedRecipients__Assembler) AssignLink(datamodel.Link) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients"}.AssignLink(nil) } -func (na *_List__Assembler) AssignNode(v datamodel.Node) error { +func (na *_EncodedRecipients__Assembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_List); ok { + if v2, ok := v.(*_EncodedRecipients); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -3954,7 +9273,7 @@ func (na *_List__Assembler) AssignNode(v datamodel.Node) error { return nil } if v.Kind() != datamodel.Kind_List { - return datamodel.ErrWrongKind{TypeName: "dagjose.List", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} + return datamodel.ErrWrongKind{TypeName: "dagjose.EncodedRecipients", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} } itr := v.ListIterator() for !itr.Done() { @@ -3968,10 +9287,10 @@ func (na *_List__Assembler) AssignNode(v datamodel.Node) error { } return na.Finish() } -func (_List__Assembler) Prototype() datamodel.NodePrototype { - return _List__Prototype{} +func (_EncodedRecipients__Assembler) Prototype() datamodel.NodePrototype { + return _EncodedRecipients__Prototype{} } -func (la *_List__Assembler) valueFinishTidy() bool { +func (la *_EncodedRecipients__Assembler) valueFinishTidy() bool { switch la.cm { case schema.Maybe_Value: la.va.w = nil @@ -3983,7 +9302,7 @@ func (la *_List__Assembler) valueFinishTidy() bool { return false } } -func (la *_List__Assembler) AssembleValue() datamodel.NodeAssembler { +func (la *_EncodedRecipients__Assembler) AssembleValue() datamodel.NodeAssembler { switch la.state { case laState_initial: // carry on @@ -3994,14 +9313,14 @@ func (la *_List__Assembler) AssembleValue() datamodel.NodeAssembler { case laState_finished: panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") } - la.w.x = append(la.w.x, _Any{}) + la.w.x = append(la.w.x, _EncodedRecipient{}) la.state = laState_midValue row := &la.w.x[len(la.w.x)-1] la.va.w = row la.va.m = &la.cm return &la.va } -func (la *_List__Assembler) Finish() error { +func (la *_EncodedRecipients__Assembler) Finish() error { switch la.state { case laState_initial: // carry on @@ -4016,139 +9335,139 @@ func (la *_List__Assembler) Finish() error { *la.m = schema.Maybe_Value return nil } -func (la *_List__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype { - return _Any__Prototype{} +func (la *_EncodedRecipients__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype { + return _EncodedRecipient__Prototype{} } -func (List) Type() schema.Type { +func (EncodedRecipients) Type() schema.Type { return nil /*TODO:typelit*/ } -func (n List) Representation() datamodel.Node { - return (*_List__Repr)(n) +func (n EncodedRecipients) Representation() datamodel.Node { + return (*_EncodedRecipients__Repr)(n) } -type _List__Repr _List +type _EncodedRecipients__Repr _EncodedRecipients -var _ datamodel.Node = &_List__Repr{} +var _ datamodel.Node = &_EncodedRecipients__Repr{} -func (_List__Repr) Kind() datamodel.Kind { +func (_EncodedRecipients__Repr) Kind() datamodel.Kind { return datamodel.Kind_List } -func (_List__Repr) LookupByString(string) (datamodel.Node, error) { - return mixins.List{TypeName: "dagjose.List.Repr"}.LookupByString("") +func (_EncodedRecipients__Repr) LookupByString(string) (datamodel.Node, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients.Repr"}.LookupByString("") } -func (nr *_List__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) { - v, err := (List)(nr).LookupByNode(k) +func (nr *_EncodedRecipients__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + v, err := (EncodedRecipients)(nr).LookupByNode(k) if err != nil || v == datamodel.Null { return v, err } - return v.(Any).Representation(), nil + return v.(EncodedRecipient).Representation(), nil } -func (nr *_List__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { - v, err := (List)(nr).LookupByIndex(idx) +func (nr *_EncodedRecipients__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + v, err := (EncodedRecipients)(nr).LookupByIndex(idx) if err != nil || v == datamodel.Null { return v, err } - return v.(Any).Representation(), nil + return v.(EncodedRecipient).Representation(), nil } -func (n _List__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { +func (n _EncodedRecipients__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { i, err := seg.Index() if err != nil { - return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.List.Repr", TroubleSegment: seg, Reason: err} + return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.EncodedRecipients.Repr", TroubleSegment: seg, Reason: err} } return n.LookupByIndex(i) } -func (_List__Repr) MapIterator() datamodel.MapIterator { +func (_EncodedRecipients__Repr) MapIterator() datamodel.MapIterator { return nil } -func (nr *_List__Repr) ListIterator() datamodel.ListIterator { - return &_List__ReprListItr{(List)(nr), 0} +func (nr *_EncodedRecipients__Repr) ListIterator() datamodel.ListIterator { + return &_EncodedRecipients__ReprListItr{(EncodedRecipients)(nr), 0} } -type _List__ReprListItr _List__ListItr +type _EncodedRecipients__ReprListItr _EncodedRecipients__ListItr -func (itr *_List__ReprListItr) Next() (idx int64, v datamodel.Node, err error) { - idx, v, err = (*_List__ListItr)(itr).Next() +func (itr *_EncodedRecipients__ReprListItr) Next() (idx int64, v datamodel.Node, err error) { + idx, v, err = (*_EncodedRecipients__ListItr)(itr).Next() if err != nil || v == datamodel.Null { return } - return idx, v.(Any).Representation(), nil + return idx, v.(EncodedRecipient).Representation(), nil } -func (itr *_List__ReprListItr) Done() bool { - return (*_List__ListItr)(itr).Done() +func (itr *_EncodedRecipients__ReprListItr) Done() bool { + return (*_EncodedRecipients__ListItr)(itr).Done() } -func (rn *_List__Repr) Length() int64 { +func (rn *_EncodedRecipients__Repr) Length() int64 { return int64(len(rn.x)) } -func (_List__Repr) IsAbsent() bool { +func (_EncodedRecipients__Repr) IsAbsent() bool { return false } -func (_List__Repr) IsNull() bool { +func (_EncodedRecipients__Repr) IsNull() bool { return false } -func (_List__Repr) AsBool() (bool, error) { - return mixins.List{TypeName: "dagjose.List.Repr"}.AsBool() +func (_EncodedRecipients__Repr) AsBool() (bool, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients.Repr"}.AsBool() } -func (_List__Repr) AsInt() (int64, error) { - return mixins.List{TypeName: "dagjose.List.Repr"}.AsInt() +func (_EncodedRecipients__Repr) AsInt() (int64, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients.Repr"}.AsInt() } -func (_List__Repr) AsFloat() (float64, error) { - return mixins.List{TypeName: "dagjose.List.Repr"}.AsFloat() +func (_EncodedRecipients__Repr) AsFloat() (float64, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients.Repr"}.AsFloat() } -func (_List__Repr) AsString() (string, error) { - return mixins.List{TypeName: "dagjose.List.Repr"}.AsString() +func (_EncodedRecipients__Repr) AsString() (string, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients.Repr"}.AsString() } -func (_List__Repr) AsBytes() ([]byte, error) { - return mixins.List{TypeName: "dagjose.List.Repr"}.AsBytes() +func (_EncodedRecipients__Repr) AsBytes() ([]byte, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients.Repr"}.AsBytes() } -func (_List__Repr) AsLink() (datamodel.Link, error) { - return mixins.List{TypeName: "dagjose.List.Repr"}.AsLink() +func (_EncodedRecipients__Repr) AsLink() (datamodel.Link, error) { + return mixins.List{TypeName: "dagjose.EncodedRecipients.Repr"}.AsLink() } -func (_List__Repr) Prototype() datamodel.NodePrototype { - return _List__ReprPrototype{} +func (_EncodedRecipients__Repr) Prototype() datamodel.NodePrototype { + return _EncodedRecipients__ReprPrototype{} } -type _List__ReprPrototype struct{} +type _EncodedRecipients__ReprPrototype struct{} -func (_List__ReprPrototype) NewBuilder() datamodel.NodeBuilder { - var nb _List__ReprBuilder +func (_EncodedRecipients__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _EncodedRecipients__ReprBuilder nb.Reset() return &nb } -type _List__ReprBuilder struct { - _List__ReprAssembler +type _EncodedRecipients__ReprBuilder struct { + _EncodedRecipients__ReprAssembler } -func (nb *_List__ReprBuilder) Build() datamodel.Node { +func (nb *_EncodedRecipients__ReprBuilder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_List__ReprBuilder) Reset() { - var w _List +func (nb *_EncodedRecipients__ReprBuilder) Reset() { + var w _EncodedRecipients var m schema.Maybe - *nb = _List__ReprBuilder{_List__ReprAssembler{w: &w, m: &m}} + *nb = _EncodedRecipients__ReprBuilder{_EncodedRecipients__ReprAssembler{w: &w, m: &m}} } -type _List__ReprAssembler struct { - w *_List +type _EncodedRecipients__ReprAssembler struct { + w *_EncodedRecipients m *schema.Maybe state laState cm schema.Maybe - va _Any__ReprAssembler + va _EncodedRecipient__ReprAssembler } -func (na *_List__ReprAssembler) reset() { +func (na *_EncodedRecipients__ReprAssembler) reset() { na.state = laState_initial na.va.reset() } -func (_List__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.BeginMap(0) +func (_EncodedRecipients__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients.Repr"}.BeginMap(0) } -func (na *_List__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { +func (na *_EncodedRecipients__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -4160,17 +9479,17 @@ func (na *_List__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembl sizeHint = 0 } if sizeHint > 0 { - na.w.x = make([]_Any, 0, sizeHint) + na.w.x = make([]_EncodedRecipient, 0, sizeHint) } return na, nil } -func (na *_List__ReprAssembler) AssignNull() error { +func (na *_EncodedRecipients__ReprAssembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.ListAssembler{TypeName: "dagjose.List.Repr.Repr"}.AssignNull() + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -4178,29 +9497,29 @@ func (na *_List__ReprAssembler) AssignNull() error { } panic("unreachable") } -func (_List__ReprAssembler) AssignBool(bool) error { - return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignBool(false) +func (_EncodedRecipients__ReprAssembler) AssignBool(bool) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients.Repr"}.AssignBool(false) } -func (_List__ReprAssembler) AssignInt(int64) error { - return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignInt(0) +func (_EncodedRecipients__ReprAssembler) AssignInt(int64) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients.Repr"}.AssignInt(0) } -func (_List__ReprAssembler) AssignFloat(float64) error { - return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignFloat(0) +func (_EncodedRecipients__ReprAssembler) AssignFloat(float64) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients.Repr"}.AssignFloat(0) } -func (_List__ReprAssembler) AssignString(string) error { - return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignString("") +func (_EncodedRecipients__ReprAssembler) AssignString(string) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients.Repr"}.AssignString("") } -func (_List__ReprAssembler) AssignBytes([]byte) error { - return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignBytes(nil) +func (_EncodedRecipients__ReprAssembler) AssignBytes([]byte) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients.Repr"}.AssignBytes(nil) } -func (_List__ReprAssembler) AssignLink(datamodel.Link) error { - return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignLink(nil) +func (_EncodedRecipients__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedRecipients.Repr"}.AssignLink(nil) } -func (na *_List__ReprAssembler) AssignNode(v datamodel.Node) error { +func (na *_EncodedRecipients__ReprAssembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_List); ok { + if v2, ok := v.(*_EncodedRecipients); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -4212,7 +9531,7 @@ func (na *_List__ReprAssembler) AssignNode(v datamodel.Node) error { return nil } if v.Kind() != datamodel.Kind_List { - return datamodel.ErrWrongKind{TypeName: "dagjose.List.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} + return datamodel.ErrWrongKind{TypeName: "dagjose.EncodedRecipients.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} } itr := v.ListIterator() for !itr.Done() { @@ -4226,10 +9545,10 @@ func (na *_List__ReprAssembler) AssignNode(v datamodel.Node) error { } return na.Finish() } -func (_List__ReprAssembler) Prototype() datamodel.NodePrototype { - return _List__ReprPrototype{} +func (_EncodedRecipients__ReprAssembler) Prototype() datamodel.NodePrototype { + return _EncodedRecipients__ReprPrototype{} } -func (la *_List__ReprAssembler) valueFinishTidy() bool { +func (la *_EncodedRecipients__ReprAssembler) valueFinishTidy() bool { switch la.cm { case schema.Maybe_Value: la.va.w = nil @@ -4241,7 +9560,7 @@ func (la *_List__ReprAssembler) valueFinishTidy() bool { return false } } -func (la *_List__ReprAssembler) AssembleValue() datamodel.NodeAssembler { +func (la *_EncodedRecipients__ReprAssembler) AssembleValue() datamodel.NodeAssembler { switch la.state { case laState_initial: // carry on @@ -4252,14 +9571,14 @@ func (la *_List__ReprAssembler) AssembleValue() datamodel.NodeAssembler { case laState_finished: panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") } - la.w.x = append(la.w.x, _Any{}) + la.w.x = append(la.w.x, _EncodedRecipient{}) la.state = laState_midValue row := &la.w.x[len(la.w.x)-1] la.va.w = row la.va.m = &la.cm return &la.va } -func (la *_List__ReprAssembler) Finish() error { +func (la *_EncodedRecipients__ReprAssembler) Finish() error { switch la.state { case laState_initial: // carry on @@ -4274,219 +9593,224 @@ func (la *_List__ReprAssembler) Finish() error { *la.m = schema.Maybe_Value return nil } -func (la *_List__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype { - return _Any__ReprPrototype{} -} - -func (n *_Map) Lookup(k String) Any { - v, exists := n.m[*k] - if !exists { - return nil - } - return v -} -func (n *_Map) LookupMaybe(k String) MaybeAny { - v, exists := n.m[*k] - if !exists { - return &_Map__valueAbsent - } - return &_Any__Maybe{ - m: schema.Maybe_Value, - v: v, - } -} - -var _Map__valueAbsent = _Any__Maybe{m: schema.Maybe_Absent} - -func (n Map) Iterator() *Map__Itr { - return &Map__Itr{n, 0} +func (la *_EncodedRecipients__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype { + return _EncodedRecipient__ReprPrototype{} } -type Map__Itr struct { - n Map - idx int +func (n _EncodedSignature) FieldHeader() MaybeAny { + return &n.header } - -func (itr *Map__Itr) Next() (k String, v Any) { - if itr.idx >= len(itr.n.t) { - return nil, nil - } - x := &itr.n.t[itr.idx] - k = &x.k - v = &x.v - itr.idx++ - return +func (n _EncodedSignature) FieldProtected() MaybeRaw { + return &n.protected } -func (itr *Map__Itr) Done() bool { - return itr.idx >= len(itr.n.t) +func (n _EncodedSignature) FieldSignature() Raw { + return &n.signature } -type _Map__Maybe struct { +type _EncodedSignature__Maybe struct { m schema.Maybe - v _Map + v EncodedSignature } -type MaybeMap = *_Map__Maybe +type MaybeEncodedSignature = *_EncodedSignature__Maybe -func (m MaybeMap) IsNull() bool { +func (m MaybeEncodedSignature) IsNull() bool { return m.m == schema.Maybe_Null } -func (m MaybeMap) IsAbsent() bool { +func (m MaybeEncodedSignature) IsAbsent() bool { return m.m == schema.Maybe_Absent } -func (m MaybeMap) Exists() bool { +func (m MaybeEncodedSignature) Exists() bool { return m.m == schema.Maybe_Value } -func (m MaybeMap) AsNode() datamodel.Node { +func (m MaybeEncodedSignature) AsNode() datamodel.Node { switch m.m { case schema.Maybe_Absent: return datamodel.Absent case schema.Maybe_Null: return datamodel.Null case schema.Maybe_Value: - return &m.v + return m.v default: panic("unreachable") } } -func (m MaybeMap) Must() Map { +func (m MaybeEncodedSignature) Must() EncodedSignature { if !m.Exists() { panic("unbox of a maybe rejected") } - return &m.v + return m.v } -var _ datamodel.Node = (Map)(&_Map{}) -var _ schema.TypedNode = (Map)(&_Map{}) +var ( + fieldName__EncodedSignature_Header = _String{"header"} + fieldName__EncodedSignature_Protected = _String{"protected"} + fieldName__EncodedSignature_Signature = _String{"signature"} +) +var _ datamodel.Node = (EncodedSignature)(&_EncodedSignature{}) +var _ schema.TypedNode = (EncodedSignature)(&_EncodedSignature{}) -func (Map) Kind() datamodel.Kind { +func (EncodedSignature) Kind() datamodel.Kind { return datamodel.Kind_Map } -func (n Map) LookupByString(k string) (datamodel.Node, error) { - var k2 _String - if err := (_String__ReprPrototype{}).fromString(&k2, k); err != nil { - return nil, err // TODO wrap in some kind of ErrInvalidKey - } - v, exists := n.m[k2] - if !exists { - return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(k)} +func (n EncodedSignature) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "header": + if n.header.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return n.header.v, nil + case "protected": + if n.protected.m == schema.Maybe_Absent { + return datamodel.Absent, nil + } + return &n.protected.v, nil + case "signature": + return &n.signature, nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} } - return v, nil } -func (n Map) LookupByNode(k datamodel.Node) (datamodel.Node, error) { - k2, ok := k.(String) - if !ok { - panic("todo invalid key type error") - // 'schema.ErrInvalidKey{TypeName:"dagjose.Map", Key:&_String{k}}' doesn't quite cut it: need room to explain the type, and it's not guaranteed k can be turned into a string at all - } - v, exists := n.m[*k2] - if !exists { - return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(k2.String())} +func (n EncodedSignature) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err } - return v, nil + return n.LookupByString(ks) } -func (Map) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Map{TypeName: "dagjose.Map"}.LookupByIndex(0) +func (EncodedSignature) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature"}.LookupByIndex(0) } -func (n Map) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { +func (n EncodedSignature) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { return n.LookupByString(seg.String()) } -func (n Map) MapIterator() datamodel.MapIterator { - return &_Map__MapItr{n, 0} +func (n EncodedSignature) MapIterator() datamodel.MapIterator { + return &_EncodedSignature__MapItr{n, 0} } -type _Map__MapItr struct { - n Map +type _EncodedSignature__MapItr struct { + n EncodedSignature idx int } -func (itr *_Map__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { - if itr.idx >= len(itr.n.t) { +func (itr *_EncodedSignature__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { + if itr.idx >= 3 { return nil, nil, datamodel.ErrIteratorOverread{} } - x := &itr.n.t[itr.idx] - k = &x.k - v = &x.v + switch itr.idx { + case 0: + k = &fieldName__EncodedSignature_Header + if itr.n.header.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = itr.n.header.v + case 1: + k = &fieldName__EncodedSignature_Protected + if itr.n.protected.m == schema.Maybe_Absent { + v = datamodel.Absent + break + } + v = &itr.n.protected.v + case 2: + k = &fieldName__EncodedSignature_Signature + v = &itr.n.signature + default: + panic("unreachable") + } itr.idx++ return } -func (itr *_Map__MapItr) Done() bool { - return itr.idx >= len(itr.n.t) +func (itr *_EncodedSignature__MapItr) Done() bool { + return itr.idx >= 3 } -func (Map) ListIterator() datamodel.ListIterator { +func (EncodedSignature) ListIterator() datamodel.ListIterator { return nil } -func (n Map) Length() int64 { - return int64(len(n.t)) +func (EncodedSignature) Length() int64 { + return 3 } -func (Map) IsAbsent() bool { +func (EncodedSignature) IsAbsent() bool { return false } -func (Map) IsNull() bool { +func (EncodedSignature) IsNull() bool { return false } -func (Map) AsBool() (bool, error) { - return mixins.Map{TypeName: "dagjose.Map"}.AsBool() +func (EncodedSignature) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature"}.AsBool() } -func (Map) AsInt() (int64, error) { - return mixins.Map{TypeName: "dagjose.Map"}.AsInt() +func (EncodedSignature) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature"}.AsInt() } -func (Map) AsFloat() (float64, error) { - return mixins.Map{TypeName: "dagjose.Map"}.AsFloat() +func (EncodedSignature) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature"}.AsFloat() } -func (Map) AsString() (string, error) { - return mixins.Map{TypeName: "dagjose.Map"}.AsString() +func (EncodedSignature) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature"}.AsString() } -func (Map) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "dagjose.Map"}.AsBytes() +func (EncodedSignature) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature"}.AsBytes() } -func (Map) AsLink() (datamodel.Link, error) { - return mixins.Map{TypeName: "dagjose.Map"}.AsLink() +func (EncodedSignature) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature"}.AsLink() } -func (Map) Prototype() datamodel.NodePrototype { - return _Map__Prototype{} +func (EncodedSignature) Prototype() datamodel.NodePrototype { + return _EncodedSignature__Prototype{} } -type _Map__Prototype struct{} +type _EncodedSignature__Prototype struct{} -func (_Map__Prototype) NewBuilder() datamodel.NodeBuilder { - var nb _Map__Builder +func (_EncodedSignature__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _EncodedSignature__Builder nb.Reset() return &nb } -type _Map__Builder struct { - _Map__Assembler +type _EncodedSignature__Builder struct { + _EncodedSignature__Assembler } -func (nb *_Map__Builder) Build() datamodel.Node { +func (nb *_EncodedSignature__Builder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Map__Builder) Reset() { - var w _Map +func (nb *_EncodedSignature__Builder) Reset() { + var w _EncodedSignature var m schema.Maybe - *nb = _Map__Builder{_Map__Assembler{w: &w, m: &m}} + *nb = _EncodedSignature__Builder{_EncodedSignature__Assembler{w: &w, m: &m}} } -type _Map__Assembler struct { - w *_Map +type _EncodedSignature__Assembler struct { + w *_EncodedSignature m *schema.Maybe state maState + s int + f int - cm schema.Maybe - ka _String__Assembler - va _Any__Assembler + cm schema.Maybe + ca_header _Any__Assembler + ca_protected _Raw__Assembler + ca_signature _Raw__Assembler } -func (na *_Map__Assembler) reset() { +func (na *_EncodedSignature__Assembler) reset() { na.state = maState_initial - na.ka.reset() - na.va.reset() + na.s = 0 + na.ca_header.reset() + na.ca_protected.reset() + na.ca_signature.reset() } -func (na *_Map__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + +var ( + fieldBit__EncodedSignature_Header = 1 << 0 + fieldBit__EncodedSignature_Protected = 1 << 1 + fieldBit__EncodedSignature_Signature = 1 << 2 + fieldBits__EncodedSignature_sufficient = 0 + 1<<2 +) + +func (na *_EncodedSignature__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -4494,23 +9818,21 @@ func (na *_Map__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, err panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") } *na.m = midvalue - if sizeHint < 0 { - sizeHint = 0 + if na.w == nil { + na.w = &_EncodedSignature{} } - na.w.m = make(map[_String]*_Any, sizeHint) - na.w.t = make([]_Map__entry, 0, sizeHint) return na, nil } -func (_Map__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.MapAssembler{TypeName: "dagjose.Map"}.BeginList(0) +func (_EncodedSignature__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature"}.BeginList(0) } -func (na *_Map__Assembler) AssignNull() error { +func (na *_EncodedSignature__Assembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignNull() + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -4518,41 +9840,46 @@ func (na *_Map__Assembler) AssignNull() error { } panic("unreachable") } -func (_Map__Assembler) AssignBool(bool) error { - return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignBool(false) +func (_EncodedSignature__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature"}.AssignBool(false) } -func (_Map__Assembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignInt(0) +func (_EncodedSignature__Assembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature"}.AssignInt(0) } -func (_Map__Assembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignFloat(0) +func (_EncodedSignature__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature"}.AssignFloat(0) } -func (_Map__Assembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignString("") +func (_EncodedSignature__Assembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature"}.AssignString("") } -func (_Map__Assembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignBytes(nil) +func (_EncodedSignature__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature"}.AssignBytes(nil) } -func (_Map__Assembler) AssignLink(datamodel.Link) error { - return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignLink(nil) +func (_EncodedSignature__Assembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature"}.AssignLink(nil) } -func (na *_Map__Assembler) AssignNode(v datamodel.Node) error { +func (na *_EncodedSignature__Assembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Map); ok { + if v2, ok := v.(*_EncodedSignature); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } *na.w = *v2 *na.m = schema.Maybe_Value return nil } if v.Kind() != datamodel.Kind_Map { - return datamodel.ErrWrongKind{TypeName: "dagjose.Map", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + return datamodel.ErrWrongKind{TypeName: "dagjose.EncodedSignature", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} } itr := v.MapIterator() for !itr.Done() { @@ -4569,38 +9896,43 @@ func (na *_Map__Assembler) AssignNode(v datamodel.Node) error { } return na.Finish() } -func (_Map__Assembler) Prototype() datamodel.NodePrototype { - return _Map__Prototype{} -} -func (ma *_Map__Assembler) keyFinishTidy() bool { - switch ma.cm { - case schema.Maybe_Value: - ma.ka.w = nil - tz := &ma.w.t[len(ma.w.t)-1] - ma.cm = schema.Maybe_Absent - ma.state = maState_expectValue - ma.w.m[tz.k] = &tz.v - ma.va.w = &tz.v - ma.va.m = &ma.cm - ma.ka.reset() - return true - default: - return false - } +func (_EncodedSignature__Assembler) Prototype() datamodel.NodePrototype { + return _EncodedSignature__Prototype{} } -func (ma *_Map__Assembler) valueFinishTidy() bool { - switch ma.cm { - case schema.Maybe_Value: - ma.va.w = nil - ma.cm = schema.Maybe_Absent - ma.state = maState_initial - ma.va.reset() - return true +func (ma *_EncodedSignature__Assembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.header.m { + case schema.Maybe_Value: + ma.w.header.v = ma.ca_header.w + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.protected.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 2: + switch ma.cm { + case schema.Maybe_Value: + ma.ca_signature.w = nil + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } default: - return false + panic("unreachable") } } -func (ma *_Map__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { +func (ma *_EncodedSignature__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { switch ma.state { case maState_initial: // carry on @@ -4615,24 +9947,41 @@ func (ma *_Map__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, err case maState_finished: panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") } - - var k2 _String - if err := (_String__ReprPrototype{}).fromString(&k2, k); err != nil { - return nil, err // TODO wrap in some kind of ErrInvalidKey - } - if _, exists := ma.w.m[k2]; exists { - return nil, datamodel.ErrRepeatedMapKey{Key: &k2} + switch k { + case "header": + if ma.s&fieldBit__EncodedSignature_Header != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Header} + } + ma.s += fieldBit__EncodedSignature_Header + ma.state = maState_midValue + ma.f = 0 + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + return &ma.ca_header, nil + case "protected": + if ma.s&fieldBit__EncodedSignature_Protected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Protected} + } + ma.s += fieldBit__EncodedSignature_Protected + ma.state = maState_midValue + ma.f = 1 + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + return &ma.ca_protected, nil + case "signature": + if ma.s&fieldBit__EncodedSignature_Signature != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Signature} + } + ma.s += fieldBit__EncodedSignature_Signature + ma.state = maState_midValue + ma.f = 2 + ma.ca_signature.w = &ma.w.signature + ma.ca_signature.m = &ma.cm + return &ma.ca_signature, nil } - ma.w.t = append(ma.w.t, _Map__entry{k: k2}) - tz := &ma.w.t[len(ma.w.t)-1] - ma.state = maState_midValue - - ma.w.m[k2] = &tz.v - ma.va.w = &tz.v - ma.va.m = &ma.cm - return &ma.va, nil + return nil, schema.ErrInvalidKey{TypeName: "dagjose.EncodedSignature", Key: &_String{k}} } -func (ma *_Map__Assembler) AssembleKey() datamodel.NodeAssembler { +func (ma *_EncodedSignature__Assembler) AssembleKey() datamodel.NodeAssembler { switch ma.state { case maState_initial: // carry on @@ -4647,20 +9996,15 @@ func (ma *_Map__Assembler) AssembleKey() datamodel.NodeAssembler { case maState_finished: panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") } - ma.w.t = append(ma.w.t, _Map__entry{}) ma.state = maState_midKey - ma.ka.m = &ma.cm - ma.ka.w = &ma.w.t[len(ma.w.t)-1].k - return &ma.ka + return (*_EncodedSignature__KeyAssembler)(ma) } -func (ma *_Map__Assembler) AssembleValue() datamodel.NodeAssembler { +func (ma *_EncodedSignature__Assembler) AssembleValue() datamodel.NodeAssembler { switch ma.state { case maState_initial: panic("invalid state: AssembleValue cannot be called when no key is primed") case maState_midKey: - if !ma.keyFinishTidy() { - panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") - } // if tidy success: carry on + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") case maState_expectValue: // carry on case maState_midValue: @@ -4669,9 +10013,24 @@ func (ma *_Map__Assembler) AssembleValue() datamodel.NodeAssembler { panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") } ma.state = maState_midValue - return &ma.va + switch ma.f { + case 0: + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + return &ma.ca_header + case 1: + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + return &ma.ca_protected + case 2: + ma.ca_signature.w = &ma.w.signature + ma.ca_signature.m = &ma.cm + return &ma.ca_signature + default: + panic("unreachable") + } } -func (ma *_Map__Assembler) Finish() error { +func (ma *_EncodedSignature__Assembler) Finish() error { switch ma.state { case maState_initial: // carry on @@ -4686,141 +10045,270 @@ func (ma *_Map__Assembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } + if ma.s&fieldBits__EncodedSignature_sufficient != fieldBits__EncodedSignature_sufficient { + err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} + if ma.s&fieldBit__EncodedSignature_Signature == 0 { + err.Missing = append(err.Missing, "signature") + } + return err + } ma.state = maState_finished *ma.m = schema.Maybe_Value return nil } -func (ma *_Map__Assembler) KeyPrototype() datamodel.NodePrototype { +func (ma *_EncodedSignature__Assembler) KeyPrototype() datamodel.NodePrototype { return _String__Prototype{} } -func (ma *_Map__Assembler) ValuePrototype(_ string) datamodel.NodePrototype { - return _Any__Prototype{} +func (ma *_EncodedSignature__Assembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler valueprototype") } -func (Map) Type() schema.Type { + +type _EncodedSignature__KeyAssembler _EncodedSignature__Assembler + +func (_EncodedSignature__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.KeyAssembler"}.BeginMap(0) +} +func (_EncodedSignature__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.KeyAssembler"}.BeginList(0) +} +func (na *_EncodedSignature__KeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.KeyAssembler"}.AssignNull() +} +func (_EncodedSignature__KeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.KeyAssembler"}.AssignBool(false) +} +func (_EncodedSignature__KeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.KeyAssembler"}.AssignInt(0) +} +func (_EncodedSignature__KeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.KeyAssembler"}.AssignFloat(0) +} +func (ka *_EncodedSignature__KeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "header": + if ka.s&fieldBit__EncodedSignature_Header != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Header} + } + ka.s += fieldBit__EncodedSignature_Header + ka.state = maState_expectValue + ka.f = 0 + return nil + case "protected": + if ka.s&fieldBit__EncodedSignature_Protected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Protected} + } + ka.s += fieldBit__EncodedSignature_Protected + ka.state = maState_expectValue + ka.f = 1 + return nil + case "signature": + if ka.s&fieldBit__EncodedSignature_Signature != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Signature} + } + ka.s += fieldBit__EncodedSignature_Signature + ka.state = maState_expectValue + ka.f = 2 + return nil + default: + return schema.ErrInvalidKey{TypeName: "dagjose.EncodedSignature", Key: &_String{k}} + } +} +func (_EncodedSignature__KeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.KeyAssembler"}.AssignBytes(nil) +} +func (_EncodedSignature__KeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.KeyAssembler"}.AssignLink(nil) +} +func (ka *_EncodedSignature__KeyAssembler) AssignNode(v datamodel.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_EncodedSignature__KeyAssembler) Prototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (EncodedSignature) Type() schema.Type { return nil /*TODO:typelit*/ } -func (n Map) Representation() datamodel.Node { - return (*_Map__Repr)(n) +func (n EncodedSignature) Representation() datamodel.Node { + return (*_EncodedSignature__Repr)(n) } -type _Map__Repr _Map +type _EncodedSignature__Repr _EncodedSignature -var _ datamodel.Node = &_Map__Repr{} +var ( + fieldName__EncodedSignature_Header_serial = _String{"header"} + fieldName__EncodedSignature_Protected_serial = _String{"protected"} + fieldName__EncodedSignature_Signature_serial = _String{"signature"} +) +var _ datamodel.Node = &_EncodedSignature__Repr{} -func (_Map__Repr) Kind() datamodel.Kind { +func (_EncodedSignature__Repr) Kind() datamodel.Kind { return datamodel.Kind_Map } -func (nr *_Map__Repr) LookupByString(k string) (datamodel.Node, error) { - v, err := (Map)(nr).LookupByString(k) - if err != nil || v == datamodel.Null { - return v, err +func (n *_EncodedSignature__Repr) LookupByString(key string) (datamodel.Node, error) { + switch key { + case "header": + if n.header.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.header.v.Representation(), nil + case "protected": + if n.protected.m == schema.Maybe_Absent { + return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} + } + return n.protected.v.Representation(), nil + case "signature": + return n.signature.Representation(), nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} } - return v.(Any).Representation(), nil } -func (nr *_Map__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) { - v, err := (Map)(nr).LookupByNode(k) - if err != nil || v == datamodel.Null { - return v, err +func (n *_EncodedSignature__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err } - return v.(Any).Representation(), nil + return n.LookupByString(ks) } -func (_Map__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Map{TypeName: "dagjose.Map.Repr"}.LookupByIndex(0) +func (_EncodedSignature__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature.Repr"}.LookupByIndex(0) } -func (n _Map__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { +func (n _EncodedSignature__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { return n.LookupByString(seg.String()) } -func (nr *_Map__Repr) MapIterator() datamodel.MapIterator { - return &_Map__ReprMapItr{(Map)(nr), 0} +func (n *_EncodedSignature__Repr) MapIterator() datamodel.MapIterator { + return &_EncodedSignature__ReprMapItr{n, 0} } -type _Map__ReprMapItr _Map__MapItr +type _EncodedSignature__ReprMapItr struct { + n *_EncodedSignature__Repr + idx int +} -func (itr *_Map__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, err error) { - k, v, err = (*_Map__MapItr)(itr).Next() - if err != nil || v == datamodel.Null { - return +func (itr *_EncodedSignature__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { +advance: + if itr.idx >= 3 { + return nil, nil, datamodel.ErrIteratorOverread{} } - return k, v.(Any).Representation(), nil + switch itr.idx { + case 0: + k = &fieldName__EncodedSignature_Header_serial + if itr.n.header.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.header.v.Representation() + case 1: + k = &fieldName__EncodedSignature_Protected_serial + if itr.n.protected.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.protected.v.Representation() + case 2: + k = &fieldName__EncodedSignature_Signature_serial + v = itr.n.signature.Representation() + default: + panic("unreachable") + } + itr.idx++ + return } -func (itr *_Map__ReprMapItr) Done() bool { - return (*_Map__MapItr)(itr).Done() +func (itr *_EncodedSignature__ReprMapItr) Done() bool { + return itr.idx >= 3 } - -func (_Map__Repr) ListIterator() datamodel.ListIterator { +func (_EncodedSignature__Repr) ListIterator() datamodel.ListIterator { return nil } -func (rn *_Map__Repr) Length() int64 { - return int64(len(rn.t)) +func (rn *_EncodedSignature__Repr) Length() int64 { + l := 3 + if rn.header.m == schema.Maybe_Absent { + l-- + } + if rn.protected.m == schema.Maybe_Absent { + l-- + } + return int64(l) } -func (_Map__Repr) IsAbsent() bool { +func (_EncodedSignature__Repr) IsAbsent() bool { return false } -func (_Map__Repr) IsNull() bool { +func (_EncodedSignature__Repr) IsNull() bool { return false } -func (_Map__Repr) AsBool() (bool, error) { - return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsBool() +func (_EncodedSignature__Repr) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature.Repr"}.AsBool() } -func (_Map__Repr) AsInt() (int64, error) { - return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsInt() +func (_EncodedSignature__Repr) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature.Repr"}.AsInt() } -func (_Map__Repr) AsFloat() (float64, error) { - return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsFloat() +func (_EncodedSignature__Repr) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature.Repr"}.AsFloat() } -func (_Map__Repr) AsString() (string, error) { - return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsString() +func (_EncodedSignature__Repr) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature.Repr"}.AsString() } -func (_Map__Repr) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsBytes() +func (_EncodedSignature__Repr) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature.Repr"}.AsBytes() } -func (_Map__Repr) AsLink() (datamodel.Link, error) { - return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsLink() +func (_EncodedSignature__Repr) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.EncodedSignature.Repr"}.AsLink() } -func (_Map__Repr) Prototype() datamodel.NodePrototype { - return _Map__ReprPrototype{} +func (_EncodedSignature__Repr) Prototype() datamodel.NodePrototype { + return _EncodedSignature__ReprPrototype{} } -type _Map__ReprPrototype struct{} +type _EncodedSignature__ReprPrototype struct{} -func (_Map__ReprPrototype) NewBuilder() datamodel.NodeBuilder { - var nb _Map__ReprBuilder +func (_EncodedSignature__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _EncodedSignature__ReprBuilder nb.Reset() return &nb } -type _Map__ReprBuilder struct { - _Map__ReprAssembler +type _EncodedSignature__ReprBuilder struct { + _EncodedSignature__ReprAssembler } -func (nb *_Map__ReprBuilder) Build() datamodel.Node { +func (nb *_EncodedSignature__ReprBuilder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Map__ReprBuilder) Reset() { - var w _Map +func (nb *_EncodedSignature__ReprBuilder) Reset() { + var w _EncodedSignature var m schema.Maybe - *nb = _Map__ReprBuilder{_Map__ReprAssembler{w: &w, m: &m}} + *nb = _EncodedSignature__ReprBuilder{_EncodedSignature__ReprAssembler{w: &w, m: &m}} } -type _Map__ReprAssembler struct { - w *_Map +type _EncodedSignature__ReprAssembler struct { + w *_EncodedSignature m *schema.Maybe state maState + s int + f int - cm schema.Maybe - ka _String__ReprAssembler - va _Any__ReprAssembler + cm schema.Maybe + ca_header _Any__ReprAssembler + ca_protected _Raw__ReprAssembler + ca_signature _Raw__ReprAssembler } -func (na *_Map__ReprAssembler) reset() { +func (na *_EncodedSignature__ReprAssembler) reset() { na.state = maState_initial - na.ka.reset() - na.va.reset() + na.s = 0 + na.ca_header.reset() + na.ca_protected.reset() + na.ca_signature.reset() } -func (na *_Map__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { +func (na *_EncodedSignature__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -4828,23 +10316,21 @@ func (na *_Map__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") } *na.m = midvalue - if sizeHint < 0 { - sizeHint = 0 + if na.w == nil { + na.w = &_EncodedSignature{} } - na.w.m = make(map[_String]*_Any, sizeHint) - na.w.t = make([]_Map__entry, 0, sizeHint) return na, nil } -func (_Map__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.BeginList(0) +func (_EncodedSignature__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature.Repr"}.BeginList(0) } -func (na *_Map__ReprAssembler) AssignNull() error { +func (na *_EncodedSignature__ReprAssembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{TypeName: "dagjose.Map.Repr.Repr"}.AssignNull() + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -4852,89 +10338,98 @@ func (na *_Map__ReprAssembler) AssignNull() error { } panic("unreachable") } -func (_Map__ReprAssembler) AssignBool(bool) error { - return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignBool(false) +func (_EncodedSignature__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature.Repr"}.AssignBool(false) } -func (_Map__ReprAssembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignInt(0) +func (_EncodedSignature__ReprAssembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature.Repr"}.AssignInt(0) } -func (_Map__ReprAssembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignFloat(0) +func (_EncodedSignature__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature.Repr"}.AssignFloat(0) } -func (_Map__ReprAssembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignString("") +func (_EncodedSignature__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature.Repr"}.AssignString("") } -func (_Map__ReprAssembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignBytes(nil) +func (_EncodedSignature__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature.Repr"}.AssignBytes(nil) } -func (_Map__ReprAssembler) AssignLink(datamodel.Link) error { - return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignLink(nil) +func (_EncodedSignature__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.EncodedSignature.Repr"}.AssignLink(nil) } -func (na *_Map__ReprAssembler) AssignNode(v datamodel.Node) error { +func (na *_EncodedSignature__ReprAssembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Map); ok { + if v2, ok := v.(*_EncodedSignature); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } *na.w = *v2 *na.m = schema.Maybe_Value return nil } if v.Kind() != datamodel.Kind_Map { - return datamodel.ErrWrongKind{TypeName: "dagjose.Map.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + return datamodel.ErrWrongKind{TypeName: "dagjose.EncodedSignature.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} } itr := v.MapIterator() for !itr.Done() { k, v, err := itr.Next() - if err != nil { - return err - } - if err := na.AssembleKey().AssignNode(k); err != nil { - return err - } - if err := na.AssembleValue().AssignNode(v); err != nil { - return err - } - } - return na.Finish() -} -func (_Map__ReprAssembler) Prototype() datamodel.NodePrototype { - return _Map__ReprPrototype{} -} -func (ma *_Map__ReprAssembler) keyFinishTidy() bool { - switch ma.cm { - case schema.Maybe_Value: - ma.ka.w = nil - tz := &ma.w.t[len(ma.w.t)-1] - ma.cm = schema.Maybe_Absent - ma.state = maState_expectValue - ma.w.m[tz.k] = &tz.v - ma.va.w = &tz.v - ma.va.m = &ma.cm - ma.ka.reset() - return true - default: - return false + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } } + return na.Finish() } -func (ma *_Map__ReprAssembler) valueFinishTidy() bool { - switch ma.cm { - case schema.Maybe_Value: - ma.va.w = nil - ma.cm = schema.Maybe_Absent - ma.state = maState_initial - ma.va.reset() - return true +func (_EncodedSignature__ReprAssembler) Prototype() datamodel.NodePrototype { + return _EncodedSignature__ReprPrototype{} +} +func (ma *_EncodedSignature__ReprAssembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.header.m { + case schema.Maybe_Value: + ma.w.header.v = ma.ca_header.w + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.protected.m { + case schema.Maybe_Value: + ma.state = maState_initial + return true + default: + return false + } + case 2: + switch ma.cm { + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } default: - return false + panic("unreachable") } } -func (ma *_Map__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { +func (ma *_EncodedSignature__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { switch ma.state { case maState_initial: // carry on @@ -4949,24 +10444,44 @@ func (ma *_Map__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, case maState_finished: panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") } + switch k { + case "header": + if ma.s&fieldBit__EncodedSignature_Header != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Header_serial} + } + ma.s += fieldBit__EncodedSignature_Header + ma.state = maState_midValue + ma.f = 0 + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m - var k2 _String - if err := (_String__ReprPrototype{}).fromString(&k2, k); err != nil { - return nil, err // TODO wrap in some kind of ErrInvalidKey - } - if _, exists := ma.w.m[k2]; exists { - return nil, datamodel.ErrRepeatedMapKey{Key: &k2} - } - ma.w.t = append(ma.w.t, _Map__entry{k: k2}) - tz := &ma.w.t[len(ma.w.t)-1] - ma.state = maState_midValue + return &ma.ca_header, nil + case "protected": + if ma.s&fieldBit__EncodedSignature_Protected != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Protected_serial} + } + ma.s += fieldBit__EncodedSignature_Protected + ma.state = maState_midValue + ma.f = 1 + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m - ma.w.m[k2] = &tz.v - ma.va.w = &tz.v - ma.va.m = &ma.cm - return &ma.va, nil + return &ma.ca_protected, nil + case "signature": + if ma.s&fieldBit__EncodedSignature_Signature != 0 { + return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Signature_serial} + } + ma.s += fieldBit__EncodedSignature_Signature + ma.state = maState_midValue + ma.f = 2 + ma.ca_signature.w = &ma.w.signature + ma.ca_signature.m = &ma.cm + return &ma.ca_signature, nil + default: + } + return nil, schema.ErrInvalidKey{TypeName: "dagjose.EncodedSignature.Repr", Key: &_String{k}} } -func (ma *_Map__ReprAssembler) AssembleKey() datamodel.NodeAssembler { +func (ma *_EncodedSignature__ReprAssembler) AssembleKey() datamodel.NodeAssembler { switch ma.state { case maState_initial: // carry on @@ -4981,20 +10496,15 @@ func (ma *_Map__ReprAssembler) AssembleKey() datamodel.NodeAssembler { case maState_finished: panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") } - ma.w.t = append(ma.w.t, _Map__entry{}) ma.state = maState_midKey - ma.ka.m = &ma.cm - ma.ka.w = &ma.w.t[len(ma.w.t)-1].k - return &ma.ka + return (*_EncodedSignature__ReprKeyAssembler)(ma) } -func (ma *_Map__ReprAssembler) AssembleValue() datamodel.NodeAssembler { +func (ma *_EncodedSignature__ReprAssembler) AssembleValue() datamodel.NodeAssembler { switch ma.state { case maState_initial: panic("invalid state: AssembleValue cannot be called when no key is primed") case maState_midKey: - if !ma.keyFinishTidy() { - panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") - } // if tidy success: carry on + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") case maState_expectValue: // carry on case maState_midValue: @@ -5003,9 +10513,26 @@ func (ma *_Map__ReprAssembler) AssembleValue() datamodel.NodeAssembler { panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") } ma.state = maState_midValue - return &ma.va + switch ma.f { + case 0: + ma.ca_header.w = ma.w.header.v + ma.ca_header.m = &ma.w.header.m + + return &ma.ca_header + case 1: + ma.ca_protected.w = &ma.w.protected.v + ma.ca_protected.m = &ma.w.protected.m + + return &ma.ca_protected + case 2: + ma.ca_signature.w = &ma.w.signature + ma.ca_signature.m = &ma.cm + return &ma.ca_signature + default: + panic("unreachable") + } } -func (ma *_Map__ReprAssembler) Finish() error { +func (ma *_EncodedSignature__ReprAssembler) Finish() error { switch ma.state { case maState_initial: // carry on @@ -5020,219 +10547,297 @@ func (ma *_Map__ReprAssembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } + if ma.s&fieldBits__EncodedSignature_sufficient != fieldBits__EncodedSignature_sufficient { + err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} + if ma.s&fieldBit__EncodedSignature_Signature == 0 { + err.Missing = append(err.Missing, "signature") + } + return err + } ma.state = maState_finished *ma.m = schema.Maybe_Value return nil } -func (ma *_Map__ReprAssembler) KeyPrototype() datamodel.NodePrototype { - return _String__ReprPrototype{} +func (ma *_EncodedSignature__ReprAssembler) KeyPrototype() datamodel.NodePrototype { + return _String__Prototype{} } -func (ma *_Map__ReprAssembler) ValuePrototype(_ string) datamodel.NodePrototype { - return _Any__ReprPrototype{} +func (ma *_EncodedSignature__ReprAssembler) ValuePrototype(k string) datamodel.NodePrototype { + panic("todo structbuilder mapassembler repr valueprototype") } -func (n _Recipient) FieldHeader() MaybeAny { - return &n.header +type _EncodedSignature__ReprKeyAssembler _EncodedSignature__ReprAssembler + +func (_EncodedSignature__ReprKeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.Repr.KeyAssembler"}.BeginMap(0) } -func (n _Recipient) FieldEncrypted_key() MaybeBase64Url { - return &n.encrypted_key +func (_EncodedSignature__ReprKeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.Repr.KeyAssembler"}.BeginList(0) +} +func (na *_EncodedSignature__ReprKeyAssembler) AssignNull() error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.Repr.KeyAssembler"}.AssignNull() +} +func (_EncodedSignature__ReprKeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.Repr.KeyAssembler"}.AssignBool(false) +} +func (_EncodedSignature__ReprKeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.Repr.KeyAssembler"}.AssignInt(0) +} +func (_EncodedSignature__ReprKeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.Repr.KeyAssembler"}.AssignFloat(0) +} +func (ka *_EncodedSignature__ReprKeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "header": + if ka.s&fieldBit__EncodedSignature_Header != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Header_serial} + } + ka.s += fieldBit__EncodedSignature_Header + ka.state = maState_expectValue + ka.f = 0 + return nil + case "protected": + if ka.s&fieldBit__EncodedSignature_Protected != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Protected_serial} + } + ka.s += fieldBit__EncodedSignature_Protected + ka.state = maState_expectValue + ka.f = 1 + return nil + case "signature": + if ka.s&fieldBit__EncodedSignature_Signature != 0 { + return datamodel.ErrRepeatedMapKey{Key: &fieldName__EncodedSignature_Signature_serial} + } + ka.s += fieldBit__EncodedSignature_Signature + ka.state = maState_expectValue + ka.f = 2 + return nil + } + return schema.ErrInvalidKey{TypeName: "dagjose.EncodedSignature.Repr", Key: &_String{k}} +} +func (_EncodedSignature__ReprKeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.Repr.KeyAssembler"}.AssignBytes(nil) +} +func (_EncodedSignature__ReprKeyAssembler) AssignLink(datamodel.Link) error { + return mixins.StringAssembler{TypeName: "dagjose.EncodedSignature.Repr.KeyAssembler"}.AssignLink(nil) +} +func (ka *_EncodedSignature__ReprKeyAssembler) AssignNode(v datamodel.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_EncodedSignature__ReprKeyAssembler) Prototype() datamodel.NodePrototype { + return _String__Prototype{} +} + +func (n *_EncodedSignatures) Lookup(idx int64) EncodedSignature { + if n.Length() <= idx { + return nil + } + v := &n.x[idx] + return v +} +func (n *_EncodedSignatures) LookupMaybe(idx int64) MaybeEncodedSignature { + if n.Length() <= idx { + return nil + } + v := &n.x[idx] + return &_EncodedSignature__Maybe{ + m: schema.Maybe_Value, + v: v, + } +} + +var _EncodedSignatures__valueAbsent = _EncodedSignature__Maybe{m: schema.Maybe_Absent} + +func (n EncodedSignatures) Iterator() *EncodedSignatures__Itr { + return &EncodedSignatures__Itr{n, 0} +} + +type EncodedSignatures__Itr struct { + n EncodedSignatures + idx int +} + +func (itr *EncodedSignatures__Itr) Next() (idx int64, v EncodedSignature) { + if itr.idx >= len(itr.n.x) { + return -1, nil + } + idx = int64(itr.idx) + v = &itr.n.x[itr.idx] + itr.idx++ + return +} +func (itr *EncodedSignatures__Itr) Done() bool { + return itr.idx >= len(itr.n.x) } -type _Recipient__Maybe struct { +type _EncodedSignatures__Maybe struct { m schema.Maybe - v Recipient + v _EncodedSignatures } -type MaybeRecipient = *_Recipient__Maybe +type MaybeEncodedSignatures = *_EncodedSignatures__Maybe -func (m MaybeRecipient) IsNull() bool { +func (m MaybeEncodedSignatures) IsNull() bool { return m.m == schema.Maybe_Null } -func (m MaybeRecipient) IsAbsent() bool { +func (m MaybeEncodedSignatures) IsAbsent() bool { return m.m == schema.Maybe_Absent } -func (m MaybeRecipient) Exists() bool { +func (m MaybeEncodedSignatures) Exists() bool { return m.m == schema.Maybe_Value } -func (m MaybeRecipient) AsNode() datamodel.Node { +func (m MaybeEncodedSignatures) AsNode() datamodel.Node { switch m.m { case schema.Maybe_Absent: return datamodel.Absent case schema.Maybe_Null: return datamodel.Null case schema.Maybe_Value: - return m.v + return &m.v default: panic("unreachable") } } -func (m MaybeRecipient) Must() Recipient { +func (m MaybeEncodedSignatures) Must() EncodedSignatures { if !m.Exists() { panic("unbox of a maybe rejected") } - return m.v + return &m.v } -var ( - fieldName__Recipient_Header = _String{"header"} - fieldName__Recipient_Encrypted_key = _String{"encrypted_key"} -) -var _ datamodel.Node = (Recipient)(&_Recipient{}) -var _ schema.TypedNode = (Recipient)(&_Recipient{}) +var _ datamodel.Node = (EncodedSignatures)(&_EncodedSignatures{}) +var _ schema.TypedNode = (EncodedSignatures)(&_EncodedSignatures{}) -func (Recipient) Kind() datamodel.Kind { - return datamodel.Kind_Map +func (EncodedSignatures) Kind() datamodel.Kind { + return datamodel.Kind_List } -func (n Recipient) LookupByString(key string) (datamodel.Node, error) { - switch key { - case "header": - if n.header.m == schema.Maybe_Absent { - return datamodel.Absent, nil - } - return n.header.v, nil - case "encrypted_key": - if n.encrypted_key.m == schema.Maybe_Absent { - return datamodel.Absent, nil - } - return &n.encrypted_key.v, nil - default: - return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} - } +func (EncodedSignatures) LookupByString(string) (datamodel.Node, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures"}.LookupByString("") } -func (n Recipient) LookupByNode(key datamodel.Node) (datamodel.Node, error) { - ks, err := key.AsString() +func (n EncodedSignatures) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + idx, err := k.AsInt() if err != nil { return nil, err } - return n.LookupByString(ks) -} -func (Recipient) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Map{TypeName: "dagjose.Recipient"}.LookupByIndex(0) -} -func (n Recipient) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - return n.LookupByString(seg.String()) -} -func (n Recipient) MapIterator() datamodel.MapIterator { - return &_Recipient__MapItr{n, 0} -} - -type _Recipient__MapItr struct { - n Recipient - idx int + return n.LookupByIndex(idx) } - -func (itr *_Recipient__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { - if itr.idx >= 2 { - return nil, nil, datamodel.ErrIteratorOverread{} +func (n EncodedSignatures) LookupByIndex(idx int64) (datamodel.Node, error) { + if n.Length() <= idx { + return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)} } - switch itr.idx { - case 0: - k = &fieldName__Recipient_Header - if itr.n.header.m == schema.Maybe_Absent { - v = datamodel.Absent - break - } - v = itr.n.header.v - case 1: - k = &fieldName__Recipient_Encrypted_key - if itr.n.encrypted_key.m == schema.Maybe_Absent { - v = datamodel.Absent - break - } - v = &itr.n.encrypted_key.v - default: - panic("unreachable") + v := &n.x[idx] + return v, nil +} +func (n EncodedSignatures) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.EncodedSignatures", TroubleSegment: seg, Reason: err} } + return n.LookupByIndex(i) +} +func (EncodedSignatures) MapIterator() datamodel.MapIterator { + return nil +} +func (n EncodedSignatures) ListIterator() datamodel.ListIterator { + return &_EncodedSignatures__ListItr{n, 0} +} + +type _EncodedSignatures__ListItr struct { + n EncodedSignatures + idx int +} + +func (itr *_EncodedSignatures__ListItr) Next() (idx int64, v datamodel.Node, _ error) { + if itr.idx >= len(itr.n.x) { + return -1, nil, datamodel.ErrIteratorOverread{} + } + idx = int64(itr.idx) + x := &itr.n.x[itr.idx] + v = x itr.idx++ return } -func (itr *_Recipient__MapItr) Done() bool { - return itr.idx >= 2 +func (itr *_EncodedSignatures__ListItr) Done() bool { + return itr.idx >= len(itr.n.x) } -func (Recipient) ListIterator() datamodel.ListIterator { - return nil -} -func (Recipient) Length() int64 { - return 2 +func (n EncodedSignatures) Length() int64 { + return int64(len(n.x)) } -func (Recipient) IsAbsent() bool { +func (EncodedSignatures) IsAbsent() bool { return false } -func (Recipient) IsNull() bool { +func (EncodedSignatures) IsNull() bool { return false } -func (Recipient) AsBool() (bool, error) { - return mixins.Map{TypeName: "dagjose.Recipient"}.AsBool() +func (EncodedSignatures) AsBool() (bool, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures"}.AsBool() } -func (Recipient) AsInt() (int64, error) { - return mixins.Map{TypeName: "dagjose.Recipient"}.AsInt() +func (EncodedSignatures) AsInt() (int64, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures"}.AsInt() } -func (Recipient) AsFloat() (float64, error) { - return mixins.Map{TypeName: "dagjose.Recipient"}.AsFloat() +func (EncodedSignatures) AsFloat() (float64, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures"}.AsFloat() } -func (Recipient) AsString() (string, error) { - return mixins.Map{TypeName: "dagjose.Recipient"}.AsString() +func (EncodedSignatures) AsString() (string, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures"}.AsString() } -func (Recipient) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "dagjose.Recipient"}.AsBytes() +func (EncodedSignatures) AsBytes() ([]byte, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures"}.AsBytes() } -func (Recipient) AsLink() (datamodel.Link, error) { - return mixins.Map{TypeName: "dagjose.Recipient"}.AsLink() +func (EncodedSignatures) AsLink() (datamodel.Link, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures"}.AsLink() } -func (Recipient) Prototype() datamodel.NodePrototype { - return _Recipient__Prototype{} +func (EncodedSignatures) Prototype() datamodel.NodePrototype { + return _EncodedSignatures__Prototype{} } -type _Recipient__Prototype struct{} +type _EncodedSignatures__Prototype struct{} -func (_Recipient__Prototype) NewBuilder() datamodel.NodeBuilder { - var nb _Recipient__Builder +func (_EncodedSignatures__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _EncodedSignatures__Builder nb.Reset() return &nb } -type _Recipient__Builder struct { - _Recipient__Assembler +type _EncodedSignatures__Builder struct { + _EncodedSignatures__Assembler } -func (nb *_Recipient__Builder) Build() datamodel.Node { +func (nb *_EncodedSignatures__Builder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Recipient__Builder) Reset() { - var w _Recipient +func (nb *_EncodedSignatures__Builder) Reset() { + var w _EncodedSignatures var m schema.Maybe - *nb = _Recipient__Builder{_Recipient__Assembler{w: &w, m: &m}} + *nb = _EncodedSignatures__Builder{_EncodedSignatures__Assembler{w: &w, m: &m}} } -type _Recipient__Assembler struct { - w *_Recipient +type _EncodedSignatures__Assembler struct { + w *_EncodedSignatures m *schema.Maybe - state maState - s int - f int + state laState - cm schema.Maybe - ca_header _Any__Assembler - ca_encrypted_key _Base64Url__Assembler + cm schema.Maybe + va _EncodedSignature__Assembler } -func (na *_Recipient__Assembler) reset() { - na.state = maState_initial - na.s = 0 - na.ca_header.reset() - na.ca_encrypted_key.reset() +func (na *_EncodedSignatures__Assembler) reset() { + na.state = laState_initial + na.va.reset() } - -var ( - fieldBit__Recipient_Header = 1 << 0 - fieldBit__Recipient_Encrypted_key = 1 << 1 - fieldBits__Recipient_sufficient = 0 -) - -func (na *_Recipient__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) { +func (_EncodedSignatures__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures"}.BeginMap(0) +} +func (na *_EncodedSignatures__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -5240,21 +10845,21 @@ func (na *_Recipient__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") } *na.m = midvalue - if na.w == nil { - na.w = &_Recipient{} + if sizeHint < 0 { + sizeHint = 0 + } + if sizeHint > 0 { + na.w.x = make([]_EncodedSignature, 0, sizeHint) } return na, nil } -func (_Recipient__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.MapAssembler{TypeName: "dagjose.Recipient"}.BeginList(0) -} -func (na *_Recipient__Assembler) AssignNull() error { +func (na *_EncodedSignatures__Assembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{TypeName: "dagjose.Recipient"}.AssignNull() + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -5262,445 +10867,235 @@ func (na *_Recipient__Assembler) AssignNull() error { } panic("unreachable") } -func (_Recipient__Assembler) AssignBool(bool) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient"}.AssignBool(false) +func (_EncodedSignatures__Assembler) AssignBool(bool) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures"}.AssignBool(false) } -func (_Recipient__Assembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient"}.AssignInt(0) +func (_EncodedSignatures__Assembler) AssignInt(int64) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures"}.AssignInt(0) } -func (_Recipient__Assembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient"}.AssignFloat(0) +func (_EncodedSignatures__Assembler) AssignFloat(float64) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures"}.AssignFloat(0) } -func (_Recipient__Assembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient"}.AssignString("") +func (_EncodedSignatures__Assembler) AssignString(string) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures"}.AssignString("") } -func (_Recipient__Assembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient"}.AssignBytes(nil) +func (_EncodedSignatures__Assembler) AssignBytes([]byte) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures"}.AssignBytes(nil) } -func (_Recipient__Assembler) AssignLink(datamodel.Link) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient"}.AssignLink(nil) +func (_EncodedSignatures__Assembler) AssignLink(datamodel.Link) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures"}.AssignLink(nil) } -func (na *_Recipient__Assembler) AssignNode(v datamodel.Node) error { +func (na *_EncodedSignatures__Assembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Recipient); ok { + if v2, ok := v.(*_EncodedSignatures); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } - if na.w == nil { - na.w = v2 - *na.m = schema.Maybe_Value - return nil - } *na.w = *v2 *na.m = schema.Maybe_Value return nil } - if v.Kind() != datamodel.Kind_Map { - return datamodel.ErrWrongKind{TypeName: "dagjose.Recipient", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + if v.Kind() != datamodel.Kind_List { + return datamodel.ErrWrongKind{TypeName: "dagjose.EncodedSignatures", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} } - itr := v.MapIterator() + itr := v.ListIterator() for !itr.Done() { - k, v, err := itr.Next() + _, v, err := itr.Next() if err != nil { return err } - if err := na.AssembleKey().AssignNode(k); err != nil { - return err - } if err := na.AssembleValue().AssignNode(v); err != nil { return err } } return na.Finish() } -func (_Recipient__Assembler) Prototype() datamodel.NodePrototype { - return _Recipient__Prototype{} +func (_EncodedSignatures__Assembler) Prototype() datamodel.NodePrototype { + return _EncodedSignatures__Prototype{} } -func (ma *_Recipient__Assembler) valueFinishTidy() bool { - switch ma.f { - case 0: - switch ma.w.header.m { - case schema.Maybe_Value: - ma.w.header.v = ma.ca_header.w - ma.state = maState_initial - return true - default: - return false - } - case 1: - switch ma.w.encrypted_key.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } +func (la *_EncodedSignatures__Assembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true default: - panic("unreachable") - } -} -func (ma *_Recipient__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { - switch ma.state { - case maState_initial: - // carry on - case maState_midKey: - panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") - case maState_expectValue: - panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") - } // if tidy success: carry on - case maState_finished: - panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") - } - switch k { - case "header": - if ma.s&fieldBit__Recipient_Header != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Recipient_Header} - } - ma.s += fieldBit__Recipient_Header - ma.state = maState_midValue - ma.f = 0 - ma.ca_header.w = ma.w.header.v - ma.ca_header.m = &ma.w.header.m - return &ma.ca_header, nil - case "encrypted_key": - if ma.s&fieldBit__Recipient_Encrypted_key != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Recipient_Encrypted_key} - } - ma.s += fieldBit__Recipient_Encrypted_key - ma.state = maState_midValue - ma.f = 1 - ma.ca_encrypted_key.w = &ma.w.encrypted_key.v - ma.ca_encrypted_key.m = &ma.w.encrypted_key.m - return &ma.ca_encrypted_key, nil + return false } - return nil, schema.ErrInvalidKey{TypeName: "dagjose.Recipient", Key: &_String{k}} } -func (ma *_Recipient__Assembler) AssembleKey() datamodel.NodeAssembler { - switch ma.state { - case maState_initial: +func (la *_EncodedSignatures__Assembler) AssembleValue() datamodel.NodeAssembler { + switch la.state { + case laState_initial: // carry on - case maState_midKey: - panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") - case maState_expectValue: - panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") } // if tidy success: carry on - case maState_finished: - panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") - } - ma.state = maState_midKey - return (*_Recipient__KeyAssembler)(ma) -} -func (ma *_Recipient__Assembler) AssembleValue() datamodel.NodeAssembler { - switch ma.state { - case maState_initial: - panic("invalid state: AssembleValue cannot be called when no key is primed") - case maState_midKey: - panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") - case maState_expectValue: - // carry on - case maState_midValue: - panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") - case maState_finished: + case laState_finished: panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") } - ma.state = maState_midValue - switch ma.f { - case 0: - ma.ca_header.w = ma.w.header.v - ma.ca_header.m = &ma.w.header.m - return &ma.ca_header - case 1: - ma.ca_encrypted_key.w = &ma.w.encrypted_key.v - ma.ca_encrypted_key.m = &ma.w.encrypted_key.m - return &ma.ca_encrypted_key - default: - panic("unreachable") - } -} -func (ma *_Recipient__Assembler) Finish() error { - switch ma.state { - case maState_initial: - // carry on - case maState_midKey: - panic("invalid state: Finish cannot be called when in the middle of assembling a key") - case maState_expectValue: - panic("invalid state: Finish cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: Finish cannot be called when in the middle of assembling a value") - } // if tidy success: carry on - case maState_finished: - panic("invalid state: Finish cannot be called on an assembler that's already finished") - } - if ma.s&fieldBits__Recipient_sufficient != fieldBits__Recipient_sufficient { - err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} - return err - } - ma.state = maState_finished - *ma.m = schema.Maybe_Value - return nil -} -func (ma *_Recipient__Assembler) KeyPrototype() datamodel.NodePrototype { - return _String__Prototype{} -} -func (ma *_Recipient__Assembler) ValuePrototype(k string) datamodel.NodePrototype { - panic("todo structbuilder mapassembler valueprototype") -} - -type _Recipient__KeyAssembler _Recipient__Assembler - -func (_Recipient__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.KeyAssembler"}.BeginMap(0) -} -func (_Recipient__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.KeyAssembler"}.BeginList(0) -} -func (na *_Recipient__KeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.KeyAssembler"}.AssignNull() -} -func (_Recipient__KeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.KeyAssembler"}.AssignBool(false) -} -func (_Recipient__KeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.KeyAssembler"}.AssignInt(0) -} -func (_Recipient__KeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.KeyAssembler"}.AssignFloat(0) -} -func (ka *_Recipient__KeyAssembler) AssignString(k string) error { - if ka.state != maState_midKey { - panic("misuse: KeyAssembler held beyond its valid lifetime") - } - switch k { - case "header": - if ka.s&fieldBit__Recipient_Header != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__Recipient_Header} - } - ka.s += fieldBit__Recipient_Header - ka.state = maState_expectValue - ka.f = 0 - return nil - case "encrypted_key": - if ka.s&fieldBit__Recipient_Encrypted_key != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__Recipient_Encrypted_key} - } - ka.s += fieldBit__Recipient_Encrypted_key - ka.state = maState_expectValue - ka.f = 1 - return nil - default: - return schema.ErrInvalidKey{TypeName: "dagjose.Recipient", Key: &_String{k}} - } -} -func (_Recipient__KeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.KeyAssembler"}.AssignBytes(nil) -} -func (_Recipient__KeyAssembler) AssignLink(datamodel.Link) error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.KeyAssembler"}.AssignLink(nil) -} -func (ka *_Recipient__KeyAssembler) AssignNode(v datamodel.Node) error { - if v2, err := v.AsString(); err != nil { - return err - } else { - return ka.AssignString(v2) - } -} -func (_Recipient__KeyAssembler) Prototype() datamodel.NodePrototype { - return _String__Prototype{} -} -func (Recipient) Type() schema.Type { - return nil /*TODO:typelit*/ -} -func (n Recipient) Representation() datamodel.Node { - return (*_Recipient__Repr)(n) -} - -type _Recipient__Repr _Recipient - -var ( - fieldName__Recipient_Header_serial = _String{"header"} - fieldName__Recipient_Encrypted_key_serial = _String{"encrypted_key"} -) -var _ datamodel.Node = &_Recipient__Repr{} - -func (_Recipient__Repr) Kind() datamodel.Kind { - return datamodel.Kind_Map -} -func (n *_Recipient__Repr) LookupByString(key string) (datamodel.Node, error) { - switch key { - case "header": - if n.header.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.header.v.Representation(), nil - case "encrypted_key": - if n.encrypted_key.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.encrypted_key.v.Representation(), nil - default: - return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} - } + la.w.x = append(la.w.x, _EncodedSignature{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va } -func (n *_Recipient__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) { - ks, err := key.AsString() - if err != nil { - return nil, err +func (la *_EncodedSignatures__Assembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") } - return n.LookupByString(ks) + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil } -func (_Recipient__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Map{TypeName: "dagjose.Recipient.Repr"}.LookupByIndex(0) +func (la *_EncodedSignatures__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype { + return _EncodedSignature__Prototype{} } -func (n _Recipient__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - return n.LookupByString(seg.String()) +func (EncodedSignatures) Type() schema.Type { + return nil /*TODO:typelit*/ } -func (n *_Recipient__Repr) MapIterator() datamodel.MapIterator { - end := 2 - if n.encrypted_key.m == schema.Maybe_Absent { - end = 1 - } else { - goto done - } - if n.header.m == schema.Maybe_Absent { - end = 0 - } else { - goto done - } -done: - return &_Recipient__ReprMapItr{n, 0, end} +func (n EncodedSignatures) Representation() datamodel.Node { + return (*_EncodedSignatures__Repr)(n) } -type _Recipient__ReprMapItr struct { - n *_Recipient__Repr - idx int - end int -} +type _EncodedSignatures__Repr _EncodedSignatures -func (itr *_Recipient__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { -advance: - if itr.idx >= 2 { - return nil, nil, datamodel.ErrIteratorOverread{} +var _ datamodel.Node = &_EncodedSignatures__Repr{} + +func (_EncodedSignatures__Repr) Kind() datamodel.Kind { + return datamodel.Kind_List +} +func (_EncodedSignatures__Repr) LookupByString(string) (datamodel.Node, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures.Repr"}.LookupByString("") +} +func (nr *_EncodedSignatures__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + v, err := (EncodedSignatures)(nr).LookupByNode(k) + if err != nil || v == datamodel.Null { + return v, err } - switch itr.idx { - case 0: - k = &fieldName__Recipient_Header_serial - if itr.n.header.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.header.v.Representation() - case 1: - k = &fieldName__Recipient_Encrypted_key_serial - if itr.n.encrypted_key.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.encrypted_key.v.Representation() - default: - panic("unreachable") + return v.(EncodedSignature).Representation(), nil +} +func (nr *_EncodedSignatures__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + v, err := (EncodedSignatures)(nr).LookupByIndex(idx) + if err != nil || v == datamodel.Null { + return v, err } - itr.idx++ - return + return v.(EncodedSignature).Representation(), nil } -func (itr *_Recipient__ReprMapItr) Done() bool { - return itr.idx >= itr.end +func (n _EncodedSignatures__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.EncodedSignatures.Repr", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) } -func (_Recipient__Repr) ListIterator() datamodel.ListIterator { +func (_EncodedSignatures__Repr) MapIterator() datamodel.MapIterator { return nil } -func (rn *_Recipient__Repr) Length() int64 { - l := 2 - if rn.header.m == schema.Maybe_Absent { - l-- - } - if rn.encrypted_key.m == schema.Maybe_Absent { - l-- +func (nr *_EncodedSignatures__Repr) ListIterator() datamodel.ListIterator { + return &_EncodedSignatures__ReprListItr{(EncodedSignatures)(nr), 0} +} + +type _EncodedSignatures__ReprListItr _EncodedSignatures__ListItr + +func (itr *_EncodedSignatures__ReprListItr) Next() (idx int64, v datamodel.Node, err error) { + idx, v, err = (*_EncodedSignatures__ListItr)(itr).Next() + if err != nil || v == datamodel.Null { + return } - return int64(l) + return idx, v.(EncodedSignature).Representation(), nil +} +func (itr *_EncodedSignatures__ReprListItr) Done() bool { + return (*_EncodedSignatures__ListItr)(itr).Done() +} + +func (rn *_EncodedSignatures__Repr) Length() int64 { + return int64(len(rn.x)) } -func (_Recipient__Repr) IsAbsent() bool { +func (_EncodedSignatures__Repr) IsAbsent() bool { return false } -func (_Recipient__Repr) IsNull() bool { +func (_EncodedSignatures__Repr) IsNull() bool { return false } -func (_Recipient__Repr) AsBool() (bool, error) { - return mixins.Map{TypeName: "dagjose.Recipient.Repr"}.AsBool() +func (_EncodedSignatures__Repr) AsBool() (bool, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures.Repr"}.AsBool() } -func (_Recipient__Repr) AsInt() (int64, error) { - return mixins.Map{TypeName: "dagjose.Recipient.Repr"}.AsInt() +func (_EncodedSignatures__Repr) AsInt() (int64, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures.Repr"}.AsInt() } -func (_Recipient__Repr) AsFloat() (float64, error) { - return mixins.Map{TypeName: "dagjose.Recipient.Repr"}.AsFloat() +func (_EncodedSignatures__Repr) AsFloat() (float64, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures.Repr"}.AsFloat() } -func (_Recipient__Repr) AsString() (string, error) { - return mixins.Map{TypeName: "dagjose.Recipient.Repr"}.AsString() +func (_EncodedSignatures__Repr) AsString() (string, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures.Repr"}.AsString() } -func (_Recipient__Repr) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "dagjose.Recipient.Repr"}.AsBytes() +func (_EncodedSignatures__Repr) AsBytes() ([]byte, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures.Repr"}.AsBytes() } -func (_Recipient__Repr) AsLink() (datamodel.Link, error) { - return mixins.Map{TypeName: "dagjose.Recipient.Repr"}.AsLink() +func (_EncodedSignatures__Repr) AsLink() (datamodel.Link, error) { + return mixins.List{TypeName: "dagjose.EncodedSignatures.Repr"}.AsLink() } -func (_Recipient__Repr) Prototype() datamodel.NodePrototype { - return _Recipient__ReprPrototype{} +func (_EncodedSignatures__Repr) Prototype() datamodel.NodePrototype { + return _EncodedSignatures__ReprPrototype{} } -type _Recipient__ReprPrototype struct{} +type _EncodedSignatures__ReprPrototype struct{} -func (_Recipient__ReprPrototype) NewBuilder() datamodel.NodeBuilder { - var nb _Recipient__ReprBuilder +func (_EncodedSignatures__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _EncodedSignatures__ReprBuilder nb.Reset() return &nb } -type _Recipient__ReprBuilder struct { - _Recipient__ReprAssembler +type _EncodedSignatures__ReprBuilder struct { + _EncodedSignatures__ReprAssembler } -func (nb *_Recipient__ReprBuilder) Build() datamodel.Node { +func (nb *_EncodedSignatures__ReprBuilder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Recipient__ReprBuilder) Reset() { - var w _Recipient +func (nb *_EncodedSignatures__ReprBuilder) Reset() { + var w _EncodedSignatures var m schema.Maybe - *nb = _Recipient__ReprBuilder{_Recipient__ReprAssembler{w: &w, m: &m}} + *nb = _EncodedSignatures__ReprBuilder{_EncodedSignatures__ReprAssembler{w: &w, m: &m}} } -type _Recipient__ReprAssembler struct { - w *_Recipient +type _EncodedSignatures__ReprAssembler struct { + w *_EncodedSignatures m *schema.Maybe - state maState - s int - f int + state laState - cm schema.Maybe - ca_header _Any__ReprAssembler - ca_encrypted_key _Base64Url__ReprAssembler + cm schema.Maybe + va _EncodedSignature__ReprAssembler } -func (na *_Recipient__ReprAssembler) reset() { - na.state = maState_initial - na.s = 0 - na.ca_header.reset() - na.ca_encrypted_key.reset() +func (na *_EncodedSignatures__ReprAssembler) reset() { + na.state = laState_initial + na.va.reset() } -func (na *_Recipient__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, error) { +func (_EncodedSignatures__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures.Repr"}.BeginMap(0) +} +func (na *_EncodedSignatures__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -5708,21 +11103,21 @@ func (na *_Recipient__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, er panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") } *na.m = midvalue - if na.w == nil { - na.w = &_Recipient{} + if sizeHint < 0 { + sizeHint = 0 + } + if sizeHint > 0 { + na.w.x = make([]_EncodedSignature, 0, sizeHint) } return na, nil } -func (_Recipient__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.MapAssembler{TypeName: "dagjose.Recipient.Repr"}.BeginList(0) -} -func (na *_Recipient__ReprAssembler) AssignNull() error { +func (na *_EncodedSignatures__ReprAssembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{TypeName: "dagjose.Recipient.Repr.Repr"}.AssignNull() + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -5730,326 +11125,335 @@ func (na *_Recipient__ReprAssembler) AssignNull() error { } panic("unreachable") } -func (_Recipient__ReprAssembler) AssignBool(bool) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient.Repr"}.AssignBool(false) +func (_EncodedSignatures__ReprAssembler) AssignBool(bool) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures.Repr"}.AssignBool(false) } -func (_Recipient__ReprAssembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient.Repr"}.AssignInt(0) +func (_EncodedSignatures__ReprAssembler) AssignInt(int64) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures.Repr"}.AssignInt(0) } -func (_Recipient__ReprAssembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient.Repr"}.AssignFloat(0) +func (_EncodedSignatures__ReprAssembler) AssignFloat(float64) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures.Repr"}.AssignFloat(0) } -func (_Recipient__ReprAssembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient.Repr"}.AssignString("") +func (_EncodedSignatures__ReprAssembler) AssignString(string) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures.Repr"}.AssignString("") } -func (_Recipient__ReprAssembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient.Repr"}.AssignBytes(nil) +func (_EncodedSignatures__ReprAssembler) AssignBytes([]byte) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures.Repr"}.AssignBytes(nil) } -func (_Recipient__ReprAssembler) AssignLink(datamodel.Link) error { - return mixins.MapAssembler{TypeName: "dagjose.Recipient.Repr"}.AssignLink(nil) +func (_EncodedSignatures__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.ListAssembler{TypeName: "dagjose.EncodedSignatures.Repr"}.AssignLink(nil) } -func (na *_Recipient__ReprAssembler) AssignNode(v datamodel.Node) error { +func (na *_EncodedSignatures__ReprAssembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Recipient); ok { + if v2, ok := v.(*_EncodedSignatures); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } - if na.w == nil { - na.w = v2 - *na.m = schema.Maybe_Value - return nil - } *na.w = *v2 *na.m = schema.Maybe_Value return nil } - if v.Kind() != datamodel.Kind_Map { - return datamodel.ErrWrongKind{TypeName: "dagjose.Recipient.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + if v.Kind() != datamodel.Kind_List { + return datamodel.ErrWrongKind{TypeName: "dagjose.EncodedSignatures.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} } - itr := v.MapIterator() + itr := v.ListIterator() for !itr.Done() { - k, v, err := itr.Next() + _, v, err := itr.Next() if err != nil { return err } - if err := na.AssembleKey().AssignNode(k); err != nil { - return err - } if err := na.AssembleValue().AssignNode(v); err != nil { return err } } return na.Finish() } -func (_Recipient__ReprAssembler) Prototype() datamodel.NodePrototype { - return _Recipient__ReprPrototype{} +func (_EncodedSignatures__ReprAssembler) Prototype() datamodel.NodePrototype { + return _EncodedSignatures__ReprPrototype{} } -func (ma *_Recipient__ReprAssembler) valueFinishTidy() bool { - switch ma.f { - case 0: - switch ma.w.header.m { - case schema.Maybe_Value: - ma.w.header.v = ma.ca_header.w - ma.state = maState_initial - return true - default: - return false - } - case 1: - switch ma.w.encrypted_key.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } +func (la *_EncodedSignatures__ReprAssembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true default: - panic("unreachable") + return false } } -func (ma *_Recipient__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { - switch ma.state { - case maState_initial: +func (la *_EncodedSignatures__ReprAssembler) AssembleValue() datamodel.NodeAssembler { + switch la.state { + case laState_initial: // carry on - case maState_midKey: - panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") - case maState_expectValue: - panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") } // if tidy success: carry on - case maState_finished: - panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") - } - switch k { - case "header": - if ma.s&fieldBit__Recipient_Header != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Recipient_Header_serial} - } - ma.s += fieldBit__Recipient_Header - ma.state = maState_midValue - ma.f = 0 - ma.ca_header.w = ma.w.header.v - ma.ca_header.m = &ma.w.header.m - - return &ma.ca_header, nil - case "encrypted_key": - if ma.s&fieldBit__Recipient_Encrypted_key != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Recipient_Encrypted_key_serial} - } - ma.s += fieldBit__Recipient_Encrypted_key - ma.state = maState_midValue - ma.f = 1 - ma.ca_encrypted_key.w = &ma.w.encrypted_key.v - ma.ca_encrypted_key.m = &ma.w.encrypted_key.m - - return &ma.ca_encrypted_key, nil - default: + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") } - return nil, schema.ErrInvalidKey{TypeName: "dagjose.Recipient.Repr", Key: &_String{k}} + la.w.x = append(la.w.x, _EncodedSignature{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va } -func (ma *_Recipient__ReprAssembler) AssembleKey() datamodel.NodeAssembler { - switch ma.state { - case maState_initial: +func (la *_EncodedSignatures__ReprAssembler) Finish() error { + switch la.state { + case laState_initial: // carry on - case maState_midKey: - panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") - case maState_expectValue: - panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") } // if tidy success: carry on - case maState_finished: - panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") } - ma.state = maState_midKey - return (*_Recipient__ReprKeyAssembler)(ma) + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_EncodedSignatures__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype { + return _EncodedSignature__ReprPrototype{} } -func (ma *_Recipient__ReprAssembler) AssembleValue() datamodel.NodeAssembler { - switch ma.state { - case maState_initial: - panic("invalid state: AssembleValue cannot be called when no key is primed") - case maState_midKey: - panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") - case maState_expectValue: - // carry on - case maState_midValue: - panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") - case maState_finished: - panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") - } - ma.state = maState_midValue - switch ma.f { - case 0: - ma.ca_header.w = ma.w.header.v - ma.ca_header.m = &ma.w.header.m - return &ma.ca_header - case 1: - ma.ca_encrypted_key.w = &ma.w.encrypted_key.v - ma.ca_encrypted_key.m = &ma.w.encrypted_key.m +func (n Float) Float() float64 { + return n.x +} +func (_Float__Prototype) FromFloat(v float64) (Float, error) { + n := _Float{v} + return &n, nil +} - return &ma.ca_encrypted_key +type _Float__Maybe struct { + m schema.Maybe + v _Float +} +type MaybeFloat = *_Float__Maybe + +func (m MaybeFloat) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeFloat) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeFloat) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeFloat) AsNode() datamodel.Node { + switch m.m { + case schema.Maybe_Absent: + return datamodel.Absent + case schema.Maybe_Null: + return datamodel.Null + case schema.Maybe_Value: + return &m.v default: panic("unreachable") } } -func (ma *_Recipient__ReprAssembler) Finish() error { - switch ma.state { - case maState_initial: - // carry on - case maState_midKey: - panic("invalid state: Finish cannot be called when in the middle of assembling a key") - case maState_expectValue: - panic("invalid state: Finish cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: Finish cannot be called when in the middle of assembling a value") - } // if tidy success: carry on - case maState_finished: - panic("invalid state: Finish cannot be called on an assembler that's already finished") - } - if ma.s&fieldBits__Recipient_sufficient != fieldBits__Recipient_sufficient { - err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} - return err +func (m MaybeFloat) Must() Float { + if !m.Exists() { + panic("unbox of a maybe rejected") } - ma.state = maState_finished - *ma.m = schema.Maybe_Value + return &m.v +} + +var _ datamodel.Node = (Float)(&_Float{}) +var _ schema.TypedNode = (Float)(&_Float{}) + +func (Float) Kind() datamodel.Kind { + return datamodel.Kind_Float +} +func (Float) LookupByString(string) (datamodel.Node, error) { + return mixins.Float{TypeName: "dagjose.Float"}.LookupByString("") +} +func (Float) LookupByNode(datamodel.Node) (datamodel.Node, error) { + return mixins.Float{TypeName: "dagjose.Float"}.LookupByNode(nil) +} +func (Float) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Float{TypeName: "dagjose.Float"}.LookupByIndex(0) +} +func (Float) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return mixins.Float{TypeName: "dagjose.Float"}.LookupBySegment(seg) +} +func (Float) MapIterator() datamodel.MapIterator { return nil } -func (ma *_Recipient__ReprAssembler) KeyPrototype() datamodel.NodePrototype { - return _String__Prototype{} +func (Float) ListIterator() datamodel.ListIterator { + return nil } -func (ma *_Recipient__ReprAssembler) ValuePrototype(k string) datamodel.NodePrototype { - panic("todo structbuilder mapassembler repr valueprototype") +func (Float) Length() int64 { + return -1 +} +func (Float) IsAbsent() bool { + return false +} +func (Float) IsNull() bool { + return false +} +func (Float) AsBool() (bool, error) { + return mixins.Float{TypeName: "dagjose.Float"}.AsBool() +} +func (Float) AsInt() (int64, error) { + return mixins.Float{TypeName: "dagjose.Float"}.AsInt() +} +func (n Float) AsFloat() (float64, error) { + return n.x, nil +} +func (Float) AsString() (string, error) { + return mixins.Float{TypeName: "dagjose.Float"}.AsString() +} +func (Float) AsBytes() ([]byte, error) { + return mixins.Float{TypeName: "dagjose.Float"}.AsBytes() +} +func (Float) AsLink() (datamodel.Link, error) { + return mixins.Float{TypeName: "dagjose.Float"}.AsLink() +} +func (Float) Prototype() datamodel.NodePrototype { + return _Float__Prototype{} } -type _Recipient__ReprKeyAssembler _Recipient__ReprAssembler +type _Float__Prototype struct{} + +func (_Float__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _Float__Builder + nb.Reset() + return &nb +} -func (_Recipient__ReprKeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.Repr.KeyAssembler"}.BeginMap(0) +type _Float__Builder struct { + _Float__Assembler } -func (_Recipient__ReprKeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.Repr.KeyAssembler"}.BeginList(0) + +func (nb *_Float__Builder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w } -func (na *_Recipient__ReprKeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.Repr.KeyAssembler"}.AssignNull() +func (nb *_Float__Builder) Reset() { + var w _Float + var m schema.Maybe + *nb = _Float__Builder{_Float__Assembler{w: &w, m: &m}} } -func (_Recipient__ReprKeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.Repr.KeyAssembler"}.AssignBool(false) + +type _Float__Assembler struct { + w *_Float + m *schema.Maybe } -func (_Recipient__ReprKeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.Repr.KeyAssembler"}.AssignInt(0) + +func (na *_Float__Assembler) reset() {} +func (_Float__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.FloatAssembler{TypeName: "dagjose.Float"}.BeginMap(0) } -func (_Recipient__ReprKeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.Repr.KeyAssembler"}.AssignFloat(0) +func (_Float__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.FloatAssembler{TypeName: "dagjose.Float"}.BeginList(0) } -func (ka *_Recipient__ReprKeyAssembler) AssignString(k string) error { - if ka.state != maState_midKey { - panic("misuse: KeyAssembler held beyond its valid lifetime") - } - switch k { - case "header": - if ka.s&fieldBit__Recipient_Header != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__Recipient_Header_serial} - } - ka.s += fieldBit__Recipient_Header - ka.state = maState_expectValue - ka.f = 0 - return nil - case "encrypted_key": - if ka.s&fieldBit__Recipient_Encrypted_key != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__Recipient_Encrypted_key_serial} - } - ka.s += fieldBit__Recipient_Encrypted_key - ka.state = maState_expectValue - ka.f = 1 +func (na *_Float__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null return nil + case schema.Maybe_Absent: + return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") } - return schema.ErrInvalidKey{TypeName: "dagjose.Recipient.Repr", Key: &_String{k}} + panic("unreachable") } -func (_Recipient__ReprKeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.Repr.KeyAssembler"}.AssignBytes(nil) +func (_Float__Assembler) AssignBool(bool) error { + return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignBool(false) } -func (_Recipient__ReprKeyAssembler) AssignLink(datamodel.Link) error { - return mixins.StringAssembler{TypeName: "dagjose.Recipient.Repr.KeyAssembler"}.AssignLink(nil) +func (_Float__Assembler) AssignInt(int64) error { + return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignInt(0) } -func (ka *_Recipient__ReprKeyAssembler) AssignNode(v datamodel.Node) error { - if v2, err := v.AsString(); err != nil { - return err - } else { - return ka.AssignString(v2) +func (na *_Float__Assembler) AssignFloat(v float64) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") } + na.w.x = v + *na.m = schema.Maybe_Value + return nil } -func (_Recipient__ReprKeyAssembler) Prototype() datamodel.NodePrototype { - return _String__Prototype{} +func (_Float__Assembler) AssignString(string) error { + return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignString("") } - -func (n *_Recipients) Lookup(idx int64) Recipient { - if n.Length() <= idx { - return nil - } - v := &n.x[idx] - return v +func (_Float__Assembler) AssignBytes([]byte) error { + return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignBytes(nil) } -func (n *_Recipients) LookupMaybe(idx int64) MaybeRecipient { - if n.Length() <= idx { +func (_Float__Assembler) AssignLink(datamodel.Link) error { + return mixins.FloatAssembler{TypeName: "dagjose.Float"}.AssignLink(nil) +} +func (na *_Float__Assembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Float); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + *na.w = *v2 + *na.m = schema.Maybe_Value return nil } - v := &n.x[idx] - return &_Recipient__Maybe{ - m: schema.Maybe_Value, - v: v, + if v2, err := v.AsFloat(); err != nil { + return err + } else { + return na.AssignFloat(v2) } } +func (_Float__Assembler) Prototype() datamodel.NodePrototype { + return _Float__Prototype{} +} +func (Float) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n Float) Representation() datamodel.Node { + return (*_Float__Repr)(n) +} -var _Recipients__valueAbsent = _Recipient__Maybe{m: schema.Maybe_Absent} +type _Float__Repr = _Float -func (n Recipients) Iterator() *Recipients__Itr { - return &Recipients__Itr{n, 0} -} +var _ datamodel.Node = &_Float__Repr{} -type Recipients__Itr struct { - n Recipients - idx int -} +type _Float__ReprPrototype = _Float__Prototype +type _Float__ReprAssembler = _Float__Assembler -func (itr *Recipients__Itr) Next() (idx int64, v Recipient) { - if itr.idx >= len(itr.n.x) { - return -1, nil - } - idx = int64(itr.idx) - v = &itr.n.x[itr.idx] - itr.idx++ - return +func (n Int) Int() int64 { + return n.x } -func (itr *Recipients__Itr) Done() bool { - return itr.idx >= len(itr.n.x) +func (_Int__Prototype) FromInt(v int64) (Int, error) { + n := _Int{v} + return &n, nil } -type _Recipients__Maybe struct { +type _Int__Maybe struct { m schema.Maybe - v _Recipients + v _Int } -type MaybeRecipients = *_Recipients__Maybe +type MaybeInt = *_Int__Maybe -func (m MaybeRecipients) IsNull() bool { +func (m MaybeInt) IsNull() bool { return m.m == schema.Maybe_Null } -func (m MaybeRecipients) IsAbsent() bool { +func (m MaybeInt) IsAbsent() bool { return m.m == schema.Maybe_Absent } -func (m MaybeRecipients) Exists() bool { +func (m MaybeInt) Exists() bool { return m.m == schema.Maybe_Value } -func (m MaybeRecipients) AsNode() datamodel.Node { +func (m MaybeInt) AsNode() datamodel.Node { switch m.m { case schema.Maybe_Absent: return datamodel.Absent @@ -6061,742 +11465,585 @@ func (m MaybeRecipients) AsNode() datamodel.Node { panic("unreachable") } } -func (m MaybeRecipients) Must() Recipients { +func (m MaybeInt) Must() Int { if !m.Exists() { panic("unbox of a maybe rejected") } return &m.v } -var _ datamodel.Node = (Recipients)(&_Recipients{}) -var _ schema.TypedNode = (Recipients)(&_Recipients{}) +var _ datamodel.Node = (Int)(&_Int{}) +var _ schema.TypedNode = (Int)(&_Int{}) -func (Recipients) Kind() datamodel.Kind { - return datamodel.Kind_List -} -func (Recipients) LookupByString(string) (datamodel.Node, error) { - return mixins.List{TypeName: "dagjose.Recipients"}.LookupByString("") -} -func (n Recipients) LookupByNode(k datamodel.Node) (datamodel.Node, error) { - idx, err := k.AsInt() - if err != nil { - return nil, err - } - return n.LookupByIndex(idx) -} -func (n Recipients) LookupByIndex(idx int64) (datamodel.Node, error) { - if n.Length() <= idx { - return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)} - } - v := &n.x[idx] - return v, nil -} -func (n Recipients) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - i, err := seg.Index() - if err != nil { - return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.Recipients", TroubleSegment: seg, Reason: err} - } - return n.LookupByIndex(i) +func (Int) Kind() datamodel.Kind { + return datamodel.Kind_Int } -func (Recipients) MapIterator() datamodel.MapIterator { - return nil +func (Int) LookupByString(string) (datamodel.Node, error) { + return mixins.Int{TypeName: "dagjose.Int"}.LookupByString("") } -func (n Recipients) ListIterator() datamodel.ListIterator { - return &_Recipients__ListItr{n, 0} +func (Int) LookupByNode(datamodel.Node) (datamodel.Node, error) { + return mixins.Int{TypeName: "dagjose.Int"}.LookupByNode(nil) } - -type _Recipients__ListItr struct { - n Recipients - idx int +func (Int) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Int{TypeName: "dagjose.Int"}.LookupByIndex(0) } - -func (itr *_Recipients__ListItr) Next() (idx int64, v datamodel.Node, _ error) { - if itr.idx >= len(itr.n.x) { - return -1, nil, datamodel.ErrIteratorOverread{} - } - idx = int64(itr.idx) - x := &itr.n.x[itr.idx] - v = x - itr.idx++ - return +func (Int) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return mixins.Int{TypeName: "dagjose.Int"}.LookupBySegment(seg) } -func (itr *_Recipients__ListItr) Done() bool { - return itr.idx >= len(itr.n.x) +func (Int) MapIterator() datamodel.MapIterator { + return nil } - -func (n Recipients) Length() int64 { - return int64(len(n.x)) +func (Int) ListIterator() datamodel.ListIterator { + return nil +} +func (Int) Length() int64 { + return -1 } -func (Recipients) IsAbsent() bool { +func (Int) IsAbsent() bool { return false } -func (Recipients) IsNull() bool { +func (Int) IsNull() bool { return false } -func (Recipients) AsBool() (bool, error) { - return mixins.List{TypeName: "dagjose.Recipients"}.AsBool() +func (Int) AsBool() (bool, error) { + return mixins.Int{TypeName: "dagjose.Int"}.AsBool() } -func (Recipients) AsInt() (int64, error) { - return mixins.List{TypeName: "dagjose.Recipients"}.AsInt() +func (n Int) AsInt() (int64, error) { + return n.x, nil } -func (Recipients) AsFloat() (float64, error) { - return mixins.List{TypeName: "dagjose.Recipients"}.AsFloat() +func (Int) AsFloat() (float64, error) { + return mixins.Int{TypeName: "dagjose.Int"}.AsFloat() } -func (Recipients) AsString() (string, error) { - return mixins.List{TypeName: "dagjose.Recipients"}.AsString() +func (Int) AsString() (string, error) { + return mixins.Int{TypeName: "dagjose.Int"}.AsString() } -func (Recipients) AsBytes() ([]byte, error) { - return mixins.List{TypeName: "dagjose.Recipients"}.AsBytes() +func (Int) AsBytes() ([]byte, error) { + return mixins.Int{TypeName: "dagjose.Int"}.AsBytes() } -func (Recipients) AsLink() (datamodel.Link, error) { - return mixins.List{TypeName: "dagjose.Recipients"}.AsLink() +func (Int) AsLink() (datamodel.Link, error) { + return mixins.Int{TypeName: "dagjose.Int"}.AsLink() } -func (Recipients) Prototype() datamodel.NodePrototype { - return _Recipients__Prototype{} +func (Int) Prototype() datamodel.NodePrototype { + return _Int__Prototype{} } -type _Recipients__Prototype struct{} +type _Int__Prototype struct{} -func (_Recipients__Prototype) NewBuilder() datamodel.NodeBuilder { - var nb _Recipients__Builder +func (_Int__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _Int__Builder nb.Reset() return &nb } -type _Recipients__Builder struct { - _Recipients__Assembler +type _Int__Builder struct { + _Int__Assembler } -func (nb *_Recipients__Builder) Build() datamodel.Node { +func (nb *_Int__Builder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Recipients__Builder) Reset() { - var w _Recipients +func (nb *_Int__Builder) Reset() { + var w _Int var m schema.Maybe - *nb = _Recipients__Builder{_Recipients__Assembler{w: &w, m: &m}} + *nb = _Int__Builder{_Int__Assembler{w: &w, m: &m}} } -type _Recipients__Assembler struct { - w *_Recipients - m *schema.Maybe - state laState - - cm schema.Maybe - va _Recipient__Assembler +type _Int__Assembler struct { + w *_Int + m *schema.Maybe } -func (na *_Recipients__Assembler) reset() { - na.state = laState_initial - na.va.reset() -} -func (_Recipients__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.ListAssembler{TypeName: "dagjose.Recipients"}.BeginMap(0) +func (na *_Int__Assembler) reset() {} +func (_Int__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.IntAssembler{TypeName: "dagjose.Int"}.BeginMap(0) } -func (na *_Recipients__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - switch *na.m { - case schema.Maybe_Value, schema.Maybe_Null: - panic("invalid state: cannot assign into assembler that's already finished") - case midvalue: - panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") - } - *na.m = midvalue - if sizeHint < 0 { - sizeHint = 0 - } - if sizeHint > 0 { - na.w.x = make([]_Recipient, 0, sizeHint) - } - return na, nil +func (_Int__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.IntAssembler{TypeName: "dagjose.Int"}.BeginList(0) } -func (na *_Recipients__Assembler) AssignNull() error { +func (na *_Int__Assembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.ListAssembler{TypeName: "dagjose.Recipients"}.AssignNull() + return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") - case midvalue: - panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } panic("unreachable") } -func (_Recipients__Assembler) AssignBool(bool) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients"}.AssignBool(false) +func (_Int__Assembler) AssignBool(bool) error { + return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignBool(false) } -func (_Recipients__Assembler) AssignInt(int64) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients"}.AssignInt(0) +func (na *_Int__Assembler) AssignInt(v int64) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + na.w.x = v + *na.m = schema.Maybe_Value + return nil } -func (_Recipients__Assembler) AssignFloat(float64) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients"}.AssignFloat(0) +func (_Int__Assembler) AssignFloat(float64) error { + return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignFloat(0) } -func (_Recipients__Assembler) AssignString(string) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients"}.AssignString("") +func (_Int__Assembler) AssignString(string) error { + return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignString("") } -func (_Recipients__Assembler) AssignBytes([]byte) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients"}.AssignBytes(nil) +func (_Int__Assembler) AssignBytes([]byte) error { + return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignBytes(nil) } -func (_Recipients__Assembler) AssignLink(datamodel.Link) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients"}.AssignLink(nil) +func (_Int__Assembler) AssignLink(datamodel.Link) error { + return mixins.IntAssembler{TypeName: "dagjose.Int"}.AssignLink(nil) } -func (na *_Recipients__Assembler) AssignNode(v datamodel.Node) error { +func (na *_Int__Assembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Recipients); ok { + if v2, ok := v.(*_Int); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") - case midvalue: - panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } *na.w = *v2 *na.m = schema.Maybe_Value return nil } - if v.Kind() != datamodel.Kind_List { - return datamodel.ErrWrongKind{TypeName: "dagjose.Recipients", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} - } - itr := v.ListIterator() - for !itr.Done() { - _, v, err := itr.Next() - if err != nil { - return err - } - if err := na.AssembleValue().AssignNode(v); err != nil { - return err - } - } - return na.Finish() -} -func (_Recipients__Assembler) Prototype() datamodel.NodePrototype { - return _Recipients__Prototype{} -} -func (la *_Recipients__Assembler) valueFinishTidy() bool { - switch la.cm { - case schema.Maybe_Value: - la.va.w = nil - la.cm = schema.Maybe_Absent - la.state = laState_initial - la.va.reset() - return true - default: - return false - } -} -func (la *_Recipients__Assembler) AssembleValue() datamodel.NodeAssembler { - switch la.state { - case laState_initial: - // carry on - case laState_midValue: - if !la.valueFinishTidy() { - panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") - } // if tidy success: carry on - case laState_finished: - panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") - } - la.w.x = append(la.w.x, _Recipient{}) - la.state = laState_midValue - row := &la.w.x[len(la.w.x)-1] - la.va.w = row - la.va.m = &la.cm - return &la.va -} -func (la *_Recipients__Assembler) Finish() error { - switch la.state { - case laState_initial: - // carry on - case laState_midValue: - if !la.valueFinishTidy() { - panic("invalid state: Finish cannot be called when in the middle of assembling a value") - } // if tidy success: carry on - case laState_finished: - panic("invalid state: Finish cannot be called on an assembler that's already finished") + if v2, err := v.AsInt(); err != nil { + return err + } else { + return na.AssignInt(v2) } - la.state = laState_finished - *la.m = schema.Maybe_Value - return nil } -func (la *_Recipients__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype { - return _Recipient__Prototype{} +func (_Int__Assembler) Prototype() datamodel.NodePrototype { + return _Int__Prototype{} } -func (Recipients) Type() schema.Type { +func (Int) Type() schema.Type { return nil /*TODO:typelit*/ } -func (n Recipients) Representation() datamodel.Node { - return (*_Recipients__Repr)(n) +func (n Int) Representation() datamodel.Node { + return (*_Int__Repr)(n) } -type _Recipients__Repr _Recipients +type _Int__Repr = _Int -var _ datamodel.Node = &_Recipients__Repr{} +var _ datamodel.Node = &_Int__Repr{} -func (_Recipients__Repr) Kind() datamodel.Kind { - return datamodel.Kind_List +type _Int__ReprPrototype = _Int__Prototype +type _Int__ReprAssembler = _Int__Assembler + +func (n Link) Link() datamodel.Link { + return n.x } -func (_Recipients__Repr) LookupByString(string) (datamodel.Node, error) { - return mixins.List{TypeName: "dagjose.Recipients.Repr"}.LookupByString("") +func (_Link__Prototype) FromLink(v datamodel.Link) (Link, error) { + n := _Link{v} + return &n, nil } -func (nr *_Recipients__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) { - v, err := (Recipients)(nr).LookupByNode(k) - if err != nil || v == datamodel.Null { - return v, err - } - return v.(Recipient).Representation(), nil + +type _Link__Maybe struct { + m schema.Maybe + v _Link } -func (nr *_Recipients__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { - v, err := (Recipients)(nr).LookupByIndex(idx) - if err != nil || v == datamodel.Null { - return v, err - } - return v.(Recipient).Representation(), nil +type MaybeLink = *_Link__Maybe + +func (m MaybeLink) IsNull() bool { + return m.m == schema.Maybe_Null } -func (n _Recipients__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - i, err := seg.Index() - if err != nil { - return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.Recipients.Repr", TroubleSegment: seg, Reason: err} - } - return n.LookupByIndex(i) +func (m MaybeLink) IsAbsent() bool { + return m.m == schema.Maybe_Absent } -func (_Recipients__Repr) MapIterator() datamodel.MapIterator { - return nil +func (m MaybeLink) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeLink) AsNode() datamodel.Node { + switch m.m { + case schema.Maybe_Absent: + return datamodel.Absent + case schema.Maybe_Null: + return datamodel.Null + case schema.Maybe_Value: + return &m.v + default: + panic("unreachable") + } } -func (nr *_Recipients__Repr) ListIterator() datamodel.ListIterator { - return &_Recipients__ReprListItr{(Recipients)(nr), 0} +func (m MaybeLink) Must() Link { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return &m.v } -type _Recipients__ReprListItr _Recipients__ListItr +var _ datamodel.Node = (Link)(&_Link{}) +var _ schema.TypedNode = (Link)(&_Link{}) -func (itr *_Recipients__ReprListItr) Next() (idx int64, v datamodel.Node, err error) { - idx, v, err = (*_Recipients__ListItr)(itr).Next() - if err != nil || v == datamodel.Null { - return - } - return idx, v.(Recipient).Representation(), nil +func (Link) Kind() datamodel.Kind { + return datamodel.Kind_Link } -func (itr *_Recipients__ReprListItr) Done() bool { - return (*_Recipients__ListItr)(itr).Done() +func (Link) LookupByString(string) (datamodel.Node, error) { + return mixins.Link{TypeName: "dagjose.Link"}.LookupByString("") } - -func (rn *_Recipients__Repr) Length() int64 { - return int64(len(rn.x)) +func (Link) LookupByNode(datamodel.Node) (datamodel.Node, error) { + return mixins.Link{TypeName: "dagjose.Link"}.LookupByNode(nil) +} +func (Link) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Link{TypeName: "dagjose.Link"}.LookupByIndex(0) +} +func (Link) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return mixins.Link{TypeName: "dagjose.Link"}.LookupBySegment(seg) +} +func (Link) MapIterator() datamodel.MapIterator { + return nil +} +func (Link) ListIterator() datamodel.ListIterator { + return nil } -func (_Recipients__Repr) IsAbsent() bool { +func (Link) Length() int64 { + return -1 +} +func (Link) IsAbsent() bool { return false } -func (_Recipients__Repr) IsNull() bool { +func (Link) IsNull() bool { return false } -func (_Recipients__Repr) AsBool() (bool, error) { - return mixins.List{TypeName: "dagjose.Recipients.Repr"}.AsBool() +func (Link) AsBool() (bool, error) { + return mixins.Link{TypeName: "dagjose.Link"}.AsBool() } -func (_Recipients__Repr) AsInt() (int64, error) { - return mixins.List{TypeName: "dagjose.Recipients.Repr"}.AsInt() +func (Link) AsInt() (int64, error) { + return mixins.Link{TypeName: "dagjose.Link"}.AsInt() } -func (_Recipients__Repr) AsFloat() (float64, error) { - return mixins.List{TypeName: "dagjose.Recipients.Repr"}.AsFloat() +func (Link) AsFloat() (float64, error) { + return mixins.Link{TypeName: "dagjose.Link"}.AsFloat() } -func (_Recipients__Repr) AsString() (string, error) { - return mixins.List{TypeName: "dagjose.Recipients.Repr"}.AsString() +func (Link) AsString() (string, error) { + return mixins.Link{TypeName: "dagjose.Link"}.AsString() } -func (_Recipients__Repr) AsBytes() ([]byte, error) { - return mixins.List{TypeName: "dagjose.Recipients.Repr"}.AsBytes() +func (Link) AsBytes() ([]byte, error) { + return mixins.Link{TypeName: "dagjose.Link"}.AsBytes() } -func (_Recipients__Repr) AsLink() (datamodel.Link, error) { - return mixins.List{TypeName: "dagjose.Recipients.Repr"}.AsLink() +func (n Link) AsLink() (datamodel.Link, error) { + return n.x, nil } -func (_Recipients__Repr) Prototype() datamodel.NodePrototype { - return _Recipients__ReprPrototype{} +func (Link) Prototype() datamodel.NodePrototype { + return _Link__Prototype{} } -type _Recipients__ReprPrototype struct{} +type _Link__Prototype struct{} -func (_Recipients__ReprPrototype) NewBuilder() datamodel.NodeBuilder { - var nb _Recipients__ReprBuilder +func (_Link__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _Link__Builder nb.Reset() return &nb } -type _Recipients__ReprBuilder struct { - _Recipients__ReprAssembler +type _Link__Builder struct { + _Link__Assembler } -func (nb *_Recipients__ReprBuilder) Build() datamodel.Node { +func (nb *_Link__Builder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Recipients__ReprBuilder) Reset() { - var w _Recipients +func (nb *_Link__Builder) Reset() { + var w _Link var m schema.Maybe - *nb = _Recipients__ReprBuilder{_Recipients__ReprAssembler{w: &w, m: &m}} + *nb = _Link__Builder{_Link__Assembler{w: &w, m: &m}} } -type _Recipients__ReprAssembler struct { - w *_Recipients - m *schema.Maybe - state laState - - cm schema.Maybe - va _Recipient__ReprAssembler +type _Link__Assembler struct { + w *_Link + m *schema.Maybe } -func (na *_Recipients__ReprAssembler) reset() { - na.state = laState_initial - na.va.reset() -} -func (_Recipients__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.ListAssembler{TypeName: "dagjose.Recipients.Repr"}.BeginMap(0) +func (na *_Link__Assembler) reset() {} +func (_Link__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.LinkAssembler{TypeName: "dagjose.Link"}.BeginMap(0) } -func (na *_Recipients__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - switch *na.m { - case schema.Maybe_Value, schema.Maybe_Null: - panic("invalid state: cannot assign into assembler that's already finished") - case midvalue: - panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") - } - *na.m = midvalue - if sizeHint < 0 { - sizeHint = 0 - } - if sizeHint > 0 { - na.w.x = make([]_Recipient, 0, sizeHint) - } - return na, nil +func (_Link__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.LinkAssembler{TypeName: "dagjose.Link"}.BeginList(0) } -func (na *_Recipients__ReprAssembler) AssignNull() error { +func (na *_Link__Assembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.ListAssembler{TypeName: "dagjose.Recipients.Repr.Repr"}.AssignNull() + return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") - case midvalue: - panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } panic("unreachable") } -func (_Recipients__ReprAssembler) AssignBool(bool) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients.Repr"}.AssignBool(false) +func (_Link__Assembler) AssignBool(bool) error { + return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignBool(false) } -func (_Recipients__ReprAssembler) AssignInt(int64) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients.Repr"}.AssignInt(0) +func (_Link__Assembler) AssignInt(int64) error { + return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignInt(0) } -func (_Recipients__ReprAssembler) AssignFloat(float64) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients.Repr"}.AssignFloat(0) +func (_Link__Assembler) AssignFloat(float64) error { + return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignFloat(0) } -func (_Recipients__ReprAssembler) AssignString(string) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients.Repr"}.AssignString("") +func (_Link__Assembler) AssignString(string) error { + return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignString("") } -func (_Recipients__ReprAssembler) AssignBytes([]byte) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients.Repr"}.AssignBytes(nil) +func (_Link__Assembler) AssignBytes([]byte) error { + return mixins.LinkAssembler{TypeName: "dagjose.Link"}.AssignBytes(nil) } -func (_Recipients__ReprAssembler) AssignLink(datamodel.Link) error { - return mixins.ListAssembler{TypeName: "dagjose.Recipients.Repr"}.AssignLink(nil) +func (na *_Link__Assembler) AssignLink(v datamodel.Link) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + na.w.x = v + *na.m = schema.Maybe_Value + return nil } -func (na *_Recipients__ReprAssembler) AssignNode(v datamodel.Node) error { +func (na *_Link__Assembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Recipients); ok { + if v2, ok := v.(*_Link); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") - case midvalue: - panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } *na.w = *v2 *na.m = schema.Maybe_Value return nil } - if v.Kind() != datamodel.Kind_List { - return datamodel.ErrWrongKind{TypeName: "dagjose.Recipients.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} - } - itr := v.ListIterator() - for !itr.Done() { - _, v, err := itr.Next() - if err != nil { - return err - } - if err := na.AssembleValue().AssignNode(v); err != nil { - return err - } + if v2, err := v.AsLink(); err != nil { + return err + } else { + return na.AssignLink(v2) } - return na.Finish() } -func (_Recipients__ReprAssembler) Prototype() datamodel.NodePrototype { - return _Recipients__ReprPrototype{} +func (_Link__Assembler) Prototype() datamodel.NodePrototype { + return _Link__Prototype{} } -func (la *_Recipients__ReprAssembler) valueFinishTidy() bool { - switch la.cm { - case schema.Maybe_Value: - la.va.w = nil - la.cm = schema.Maybe_Absent - la.state = laState_initial - la.va.reset() - return true - default: - return false - } +func (Link) Type() schema.Type { + return nil /*TODO:typelit*/ } -func (la *_Recipients__ReprAssembler) AssembleValue() datamodel.NodeAssembler { - switch la.state { - case laState_initial: - // carry on - case laState_midValue: - if !la.valueFinishTidy() { - panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") - } // if tidy success: carry on - case laState_finished: - panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") +func (n Link) Representation() datamodel.Node { + return (*_Link__Repr)(n) +} + +type _Link__Repr = _Link + +var _ datamodel.Node = &_Link__Repr{} + +type _Link__ReprPrototype = _Link__Prototype +type _Link__ReprAssembler = _Link__Assembler + +func (n *_List) Lookup(idx int64) Any { + if n.Length() <= idx { + return nil } - la.w.x = append(la.w.x, _Recipient{}) - la.state = laState_midValue - row := &la.w.x[len(la.w.x)-1] - la.va.w = row - la.va.m = &la.cm - return &la.va + v := &n.x[idx] + return v } -func (la *_Recipients__ReprAssembler) Finish() error { - switch la.state { - case laState_initial: - // carry on - case laState_midValue: - if !la.valueFinishTidy() { - panic("invalid state: Finish cannot be called when in the middle of assembling a value") - } // if tidy success: carry on - case laState_finished: - panic("invalid state: Finish cannot be called on an assembler that's already finished") +func (n *_List) LookupMaybe(idx int64) MaybeAny { + if n.Length() <= idx { + return nil + } + v := &n.x[idx] + return &_Any__Maybe{ + m: schema.Maybe_Value, + v: v, } - la.state = laState_finished - *la.m = schema.Maybe_Value - return nil } -func (la *_Recipients__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype { - return _Recipient__ReprPrototype{} + +var _List__valueAbsent = _Any__Maybe{m: schema.Maybe_Absent} + +func (n List) Iterator() *List__Itr { + return &List__Itr{n, 0} } -func (n _Signature) FieldHeader() MaybeAny { - return &n.header +type List__Itr struct { + n List + idx int } -func (n _Signature) FieldProtected() MaybeBase64Url { - return &n.protected + +func (itr *List__Itr) Next() (idx int64, v Any) { + if itr.idx >= len(itr.n.x) { + return -1, nil + } + idx = int64(itr.idx) + v = &itr.n.x[itr.idx] + itr.idx++ + return } -func (n _Signature) FieldSignature() Base64Url { - return &n.signature +func (itr *List__Itr) Done() bool { + return itr.idx >= len(itr.n.x) } -type _Signature__Maybe struct { +type _List__Maybe struct { m schema.Maybe - v Signature + v _List } -type MaybeSignature = *_Signature__Maybe +type MaybeList = *_List__Maybe -func (m MaybeSignature) IsNull() bool { +func (m MaybeList) IsNull() bool { return m.m == schema.Maybe_Null } -func (m MaybeSignature) IsAbsent() bool { +func (m MaybeList) IsAbsent() bool { return m.m == schema.Maybe_Absent } -func (m MaybeSignature) Exists() bool { +func (m MaybeList) Exists() bool { return m.m == schema.Maybe_Value } -func (m MaybeSignature) AsNode() datamodel.Node { +func (m MaybeList) AsNode() datamodel.Node { switch m.m { case schema.Maybe_Absent: return datamodel.Absent case schema.Maybe_Null: return datamodel.Null case schema.Maybe_Value: - return m.v + return &m.v default: panic("unreachable") } } -func (m MaybeSignature) Must() Signature { +func (m MaybeList) Must() List { if !m.Exists() { panic("unbox of a maybe rejected") } - return m.v + return &m.v } -var ( - fieldName__Signature_Header = _String{"header"} - fieldName__Signature_Protected = _String{"protected"} - fieldName__Signature_Signature = _String{"signature"} -) -var _ datamodel.Node = (Signature)(&_Signature{}) -var _ schema.TypedNode = (Signature)(&_Signature{}) +var _ datamodel.Node = (List)(&_List{}) +var _ schema.TypedNode = (List)(&_List{}) -func (Signature) Kind() datamodel.Kind { - return datamodel.Kind_Map +func (List) Kind() datamodel.Kind { + return datamodel.Kind_List } -func (n Signature) LookupByString(key string) (datamodel.Node, error) { - switch key { - case "header": - if n.header.m == schema.Maybe_Absent { - return datamodel.Absent, nil - } - return n.header.v, nil - case "protected": - if n.protected.m == schema.Maybe_Absent { - return datamodel.Absent, nil - } - return &n.protected.v, nil - case "signature": - return &n.signature, nil - default: - return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} - } +func (List) LookupByString(string) (datamodel.Node, error) { + return mixins.List{TypeName: "dagjose.List"}.LookupByString("") } -func (n Signature) LookupByNode(key datamodel.Node) (datamodel.Node, error) { - ks, err := key.AsString() +func (n List) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + idx, err := k.AsInt() if err != nil { return nil, err } - return n.LookupByString(ks) + return n.LookupByIndex(idx) } -func (Signature) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Map{TypeName: "dagjose.Signature"}.LookupByIndex(0) +func (n List) LookupByIndex(idx int64) (datamodel.Node, error) { + if n.Length() <= idx { + return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)} + } + v := &n.x[idx] + return v, nil } -func (n Signature) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - return n.LookupByString(seg.String()) +func (n List) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.List", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (List) MapIterator() datamodel.MapIterator { + return nil } -func (n Signature) MapIterator() datamodel.MapIterator { - return &_Signature__MapItr{n, 0} +func (n List) ListIterator() datamodel.ListIterator { + return &_List__ListItr{n, 0} } -type _Signature__MapItr struct { - n Signature +type _List__ListItr struct { + n List idx int } -func (itr *_Signature__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { - if itr.idx >= 3 { - return nil, nil, datamodel.ErrIteratorOverread{} - } - switch itr.idx { - case 0: - k = &fieldName__Signature_Header - if itr.n.header.m == schema.Maybe_Absent { - v = datamodel.Absent - break - } - v = itr.n.header.v - case 1: - k = &fieldName__Signature_Protected - if itr.n.protected.m == schema.Maybe_Absent { - v = datamodel.Absent - break - } - v = &itr.n.protected.v - case 2: - k = &fieldName__Signature_Signature - v = &itr.n.signature - default: - panic("unreachable") +func (itr *_List__ListItr) Next() (idx int64, v datamodel.Node, _ error) { + if itr.idx >= len(itr.n.x) { + return -1, nil, datamodel.ErrIteratorOverread{} } + idx = int64(itr.idx) + x := &itr.n.x[itr.idx] + v = x itr.idx++ return } -func (itr *_Signature__MapItr) Done() bool { - return itr.idx >= 3 +func (itr *_List__ListItr) Done() bool { + return itr.idx >= len(itr.n.x) } -func (Signature) ListIterator() datamodel.ListIterator { - return nil -} -func (Signature) Length() int64 { - return 3 +func (n List) Length() int64 { + return int64(len(n.x)) } -func (Signature) IsAbsent() bool { +func (List) IsAbsent() bool { return false } -func (Signature) IsNull() bool { +func (List) IsNull() bool { return false } -func (Signature) AsBool() (bool, error) { - return mixins.Map{TypeName: "dagjose.Signature"}.AsBool() +func (List) AsBool() (bool, error) { + return mixins.List{TypeName: "dagjose.List"}.AsBool() } -func (Signature) AsInt() (int64, error) { - return mixins.Map{TypeName: "dagjose.Signature"}.AsInt() +func (List) AsInt() (int64, error) { + return mixins.List{TypeName: "dagjose.List"}.AsInt() } -func (Signature) AsFloat() (float64, error) { - return mixins.Map{TypeName: "dagjose.Signature"}.AsFloat() +func (List) AsFloat() (float64, error) { + return mixins.List{TypeName: "dagjose.List"}.AsFloat() } -func (Signature) AsString() (string, error) { - return mixins.Map{TypeName: "dagjose.Signature"}.AsString() +func (List) AsString() (string, error) { + return mixins.List{TypeName: "dagjose.List"}.AsString() } -func (Signature) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "dagjose.Signature"}.AsBytes() +func (List) AsBytes() ([]byte, error) { + return mixins.List{TypeName: "dagjose.List"}.AsBytes() } -func (Signature) AsLink() (datamodel.Link, error) { - return mixins.Map{TypeName: "dagjose.Signature"}.AsLink() +func (List) AsLink() (datamodel.Link, error) { + return mixins.List{TypeName: "dagjose.List"}.AsLink() } -func (Signature) Prototype() datamodel.NodePrototype { - return _Signature__Prototype{} +func (List) Prototype() datamodel.NodePrototype { + return _List__Prototype{} } -type _Signature__Prototype struct{} +type _List__Prototype struct{} -func (_Signature__Prototype) NewBuilder() datamodel.NodeBuilder { - var nb _Signature__Builder +func (_List__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _List__Builder nb.Reset() return &nb } -type _Signature__Builder struct { - _Signature__Assembler +type _List__Builder struct { + _List__Assembler } -func (nb *_Signature__Builder) Build() datamodel.Node { +func (nb *_List__Builder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Signature__Builder) Reset() { - var w _Signature +func (nb *_List__Builder) Reset() { + var w _List var m schema.Maybe - *nb = _Signature__Builder{_Signature__Assembler{w: &w, m: &m}} + *nb = _List__Builder{_List__Assembler{w: &w, m: &m}} } -type _Signature__Assembler struct { - w *_Signature +type _List__Assembler struct { + w *_List m *schema.Maybe - state maState - s int - f int + state laState - cm schema.Maybe - ca_header _Any__Assembler - ca_protected _Base64Url__Assembler - ca_signature _Base64Url__Assembler + cm schema.Maybe + va _Any__Assembler } -func (na *_Signature__Assembler) reset() { - na.state = maState_initial - na.s = 0 - na.ca_header.reset() - na.ca_protected.reset() - na.ca_signature.reset() +func (na *_List__Assembler) reset() { + na.state = laState_initial + na.va.reset() } - -var ( - fieldBit__Signature_Header = 1 << 0 - fieldBit__Signature_Protected = 1 << 1 - fieldBit__Signature_Signature = 1 << 2 - fieldBits__Signature_sufficient = 0 + 1<<2 -) - -func (na *_Signature__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) { +func (_List__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.ListAssembler{TypeName: "dagjose.List"}.BeginMap(0) +} +func (na *_List__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -6804,21 +12051,21 @@ func (na *_Signature__Assembler) BeginMap(int64) (datamodel.MapAssembler, error) panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") } *na.m = midvalue - if na.w == nil { - na.w = &_Signature{} + if sizeHint < 0 { + sizeHint = 0 + } + if sizeHint > 0 { + na.w.x = make([]_Any, 0, sizeHint) } return na, nil } -func (_Signature__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.MapAssembler{TypeName: "dagjose.Signature"}.BeginList(0) -} -func (na *_Signature__Assembler) AssignNull() error { +func (na *_List__Assembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{TypeName: "dagjose.Signature"}.AssignNull() + return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -6826,475 +12073,235 @@ func (na *_Signature__Assembler) AssignNull() error { } panic("unreachable") } -func (_Signature__Assembler) AssignBool(bool) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature"}.AssignBool(false) -} -func (_Signature__Assembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature"}.AssignInt(0) -} -func (_Signature__Assembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature"}.AssignFloat(0) -} -func (_Signature__Assembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature"}.AssignString("") -} -func (_Signature__Assembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature"}.AssignBytes(nil) -} -func (_Signature__Assembler) AssignLink(datamodel.Link) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature"}.AssignLink(nil) -} -func (na *_Signature__Assembler) AssignNode(v datamodel.Node) error { - if v.IsNull() { - return na.AssignNull() - } - if v2, ok := v.(*_Signature); ok { - switch *na.m { - case schema.Maybe_Value, schema.Maybe_Null: - panic("invalid state: cannot assign into assembler that's already finished") - case midvalue: - panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") - } - if na.w == nil { - na.w = v2 - *na.m = schema.Maybe_Value - return nil - } - *na.w = *v2 - *na.m = schema.Maybe_Value - return nil - } - if v.Kind() != datamodel.Kind_Map { - return datamodel.ErrWrongKind{TypeName: "dagjose.Signature", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} - } - itr := v.MapIterator() - for !itr.Done() { - k, v, err := itr.Next() - if err != nil { - return err - } - if err := na.AssembleKey().AssignNode(k); err != nil { - return err - } - if err := na.AssembleValue().AssignNode(v); err != nil { - return err - } - } - return na.Finish() -} -func (_Signature__Assembler) Prototype() datamodel.NodePrototype { - return _Signature__Prototype{} -} -func (ma *_Signature__Assembler) valueFinishTidy() bool { - switch ma.f { - case 0: - switch ma.w.header.m { - case schema.Maybe_Value: - ma.w.header.v = ma.ca_header.w - ma.state = maState_initial - return true - default: - return false - } - case 1: - switch ma.w.protected.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 2: - switch ma.cm { - case schema.Maybe_Value: - ma.ca_signature.w = nil - ma.cm = schema.Maybe_Absent - ma.state = maState_initial - return true - default: - return false - } - default: - panic("unreachable") - } -} -func (ma *_Signature__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { - switch ma.state { - case maState_initial: - // carry on - case maState_midKey: - panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") - case maState_expectValue: - panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") - } // if tidy success: carry on - case maState_finished: - panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") - } - switch k { - case "header": - if ma.s&fieldBit__Signature_Header != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Header} - } - ma.s += fieldBit__Signature_Header - ma.state = maState_midValue - ma.f = 0 - ma.ca_header.w = ma.w.header.v - ma.ca_header.m = &ma.w.header.m - return &ma.ca_header, nil - case "protected": - if ma.s&fieldBit__Signature_Protected != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Protected} - } - ma.s += fieldBit__Signature_Protected - ma.state = maState_midValue - ma.f = 1 - ma.ca_protected.w = &ma.w.protected.v - ma.ca_protected.m = &ma.w.protected.m - return &ma.ca_protected, nil - case "signature": - if ma.s&fieldBit__Signature_Signature != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Signature} - } - ma.s += fieldBit__Signature_Signature - ma.state = maState_midValue - ma.f = 2 - ma.ca_signature.w = &ma.w.signature - ma.ca_signature.m = &ma.cm - return &ma.ca_signature, nil - } - return nil, schema.ErrInvalidKey{TypeName: "dagjose.Signature", Key: &_String{k}} -} -func (ma *_Signature__Assembler) AssembleKey() datamodel.NodeAssembler { - switch ma.state { - case maState_initial: - // carry on - case maState_midKey: - panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") - case maState_expectValue: - panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") - } // if tidy success: carry on - case maState_finished: - panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") - } - ma.state = maState_midKey - return (*_Signature__KeyAssembler)(ma) -} -func (ma *_Signature__Assembler) AssembleValue() datamodel.NodeAssembler { - switch ma.state { - case maState_initial: - panic("invalid state: AssembleValue cannot be called when no key is primed") - case maState_midKey: - panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") - case maState_expectValue: - // carry on - case maState_midValue: - panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") - case maState_finished: - panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") - } - ma.state = maState_midValue - switch ma.f { - case 0: - ma.ca_header.w = ma.w.header.v - ma.ca_header.m = &ma.w.header.m - return &ma.ca_header - case 1: - ma.ca_protected.w = &ma.w.protected.v - ma.ca_protected.m = &ma.w.protected.m - return &ma.ca_protected - case 2: - ma.ca_signature.w = &ma.w.signature - ma.ca_signature.m = &ma.cm - return &ma.ca_signature - default: - panic("unreachable") - } -} -func (ma *_Signature__Assembler) Finish() error { - switch ma.state { - case maState_initial: - // carry on - case maState_midKey: - panic("invalid state: Finish cannot be called when in the middle of assembling a key") - case maState_expectValue: - panic("invalid state: Finish cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: Finish cannot be called when in the middle of assembling a value") - } // if tidy success: carry on - case maState_finished: - panic("invalid state: Finish cannot be called on an assembler that's already finished") - } - if ma.s&fieldBits__Signature_sufficient != fieldBits__Signature_sufficient { - err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} - if ma.s&fieldBit__Signature_Signature == 0 { - err.Missing = append(err.Missing, "signature") - } - return err - } - ma.state = maState_finished - *ma.m = schema.Maybe_Value - return nil -} -func (ma *_Signature__Assembler) KeyPrototype() datamodel.NodePrototype { - return _String__Prototype{} -} -func (ma *_Signature__Assembler) ValuePrototype(k string) datamodel.NodePrototype { - panic("todo structbuilder mapassembler valueprototype") -} - -type _Signature__KeyAssembler _Signature__Assembler - -func (_Signature__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.Signature.KeyAssembler"}.BeginMap(0) +func (_List__Assembler) AssignBool(bool) error { + return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignBool(false) } -func (_Signature__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.Signature.KeyAssembler"}.BeginList(0) +func (_List__Assembler) AssignInt(int64) error { + return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignInt(0) } -func (na *_Signature__KeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.KeyAssembler"}.AssignNull() +func (_List__Assembler) AssignFloat(float64) error { + return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignFloat(0) } -func (_Signature__KeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.KeyAssembler"}.AssignBool(false) +func (_List__Assembler) AssignString(string) error { + return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignString("") } -func (_Signature__KeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.KeyAssembler"}.AssignInt(0) +func (_List__Assembler) AssignBytes([]byte) error { + return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignBytes(nil) } -func (_Signature__KeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.KeyAssembler"}.AssignFloat(0) +func (_List__Assembler) AssignLink(datamodel.Link) error { + return mixins.ListAssembler{TypeName: "dagjose.List"}.AssignLink(nil) } -func (ka *_Signature__KeyAssembler) AssignString(k string) error { - if ka.state != maState_midKey { - panic("misuse: KeyAssembler held beyond its valid lifetime") +func (na *_List__Assembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() } - switch k { - case "header": - if ka.s&fieldBit__Signature_Header != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Header} + if v2, ok := v.(*_List); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } - ka.s += fieldBit__Signature_Header - ka.state = maState_expectValue - ka.f = 0 + *na.w = *v2 + *na.m = schema.Maybe_Value return nil - case "protected": - if ka.s&fieldBit__Signature_Protected != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Protected} + } + if v.Kind() != datamodel.Kind_List { + return datamodel.ErrWrongKind{TypeName: "dagjose.List", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err } - ka.s += fieldBit__Signature_Protected - ka.state = maState_expectValue - ka.f = 1 - return nil - case "signature": - if ka.s&fieldBit__Signature_Signature != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Signature} + if err := na.AssembleValue().AssignNode(v); err != nil { + return err } - ka.s += fieldBit__Signature_Signature - ka.state = maState_expectValue - ka.f = 2 - return nil - default: - return schema.ErrInvalidKey{TypeName: "dagjose.Signature", Key: &_String{k}} } + return na.Finish() } -func (_Signature__KeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.KeyAssembler"}.AssignBytes(nil) +func (_List__Assembler) Prototype() datamodel.NodePrototype { + return _List__Prototype{} } -func (_Signature__KeyAssembler) AssignLink(datamodel.Link) error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.KeyAssembler"}.AssignLink(nil) +func (la *_List__Assembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } } -func (ka *_Signature__KeyAssembler) AssignNode(v datamodel.Node) error { - if v2, err := v.AsString(); err != nil { - return err - } else { - return ka.AssignString(v2) +func (la *_List__Assembler) AssembleValue() datamodel.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") } + la.w.x = append(la.w.x, _Any{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va } -func (_Signature__KeyAssembler) Prototype() datamodel.NodePrototype { - return _String__Prototype{} +func (la *_List__Assembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_List__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype { + return _Any__Prototype{} } -func (Signature) Type() schema.Type { +func (List) Type() schema.Type { return nil /*TODO:typelit*/ } -func (n Signature) Representation() datamodel.Node { - return (*_Signature__Repr)(n) +func (n List) Representation() datamodel.Node { + return (*_List__Repr)(n) } -type _Signature__Repr _Signature +type _List__Repr _List -var ( - fieldName__Signature_Header_serial = _String{"header"} - fieldName__Signature_Protected_serial = _String{"protected"} - fieldName__Signature_Signature_serial = _String{"signature"} -) -var _ datamodel.Node = &_Signature__Repr{} +var _ datamodel.Node = &_List__Repr{} -func (_Signature__Repr) Kind() datamodel.Kind { - return datamodel.Kind_Map +func (_List__Repr) Kind() datamodel.Kind { + return datamodel.Kind_List } -func (n *_Signature__Repr) LookupByString(key string) (datamodel.Node, error) { - switch key { - case "header": - if n.header.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.header.v.Representation(), nil - case "protected": - if n.protected.m == schema.Maybe_Absent { - return datamodel.Absent, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)} - } - return n.protected.v.Representation(), nil - case "signature": - return n.signature.Representation(), nil - default: - return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)} +func (_List__Repr) LookupByString(string) (datamodel.Node, error) { + return mixins.List{TypeName: "dagjose.List.Repr"}.LookupByString("") +} +func (nr *_List__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + v, err := (List)(nr).LookupByNode(k) + if err != nil || v == datamodel.Null { + return v, err } + return v.(Any).Representation(), nil } -func (n *_Signature__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) { - ks, err := key.AsString() - if err != nil { - return nil, err +func (nr *_List__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + v, err := (List)(nr).LookupByIndex(idx) + if err != nil || v == datamodel.Null { + return v, err } - return n.LookupByString(ks) + return v.(Any).Representation(), nil } -func (_Signature__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { - return mixins.Map{TypeName: "dagjose.Signature.Repr"}.LookupByIndex(0) +func (n _List__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.List.Repr", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) } -func (n _Signature__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - return n.LookupByString(seg.String()) +func (_List__Repr) MapIterator() datamodel.MapIterator { + return nil } -func (n *_Signature__Repr) MapIterator() datamodel.MapIterator { - return &_Signature__ReprMapItr{n, 0} +func (nr *_List__Repr) ListIterator() datamodel.ListIterator { + return &_List__ReprListItr{(List)(nr), 0} } -type _Signature__ReprMapItr struct { - n *_Signature__Repr - idx int -} +type _List__ReprListItr _List__ListItr -func (itr *_Signature__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { -advance: - if itr.idx >= 3 { - return nil, nil, datamodel.ErrIteratorOverread{} - } - switch itr.idx { - case 0: - k = &fieldName__Signature_Header_serial - if itr.n.header.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.header.v.Representation() - case 1: - k = &fieldName__Signature_Protected_serial - if itr.n.protected.m == schema.Maybe_Absent { - itr.idx++ - goto advance - } - v = itr.n.protected.v.Representation() - case 2: - k = &fieldName__Signature_Signature_serial - v = itr.n.signature.Representation() - default: - panic("unreachable") +func (itr *_List__ReprListItr) Next() (idx int64, v datamodel.Node, err error) { + idx, v, err = (*_List__ListItr)(itr).Next() + if err != nil || v == datamodel.Null { + return } - itr.idx++ - return -} -func (itr *_Signature__ReprMapItr) Done() bool { - return itr.idx >= 3 + return idx, v.(Any).Representation(), nil } -func (_Signature__Repr) ListIterator() datamodel.ListIterator { - return nil +func (itr *_List__ReprListItr) Done() bool { + return (*_List__ListItr)(itr).Done() } -func (rn *_Signature__Repr) Length() int64 { - l := 3 - if rn.header.m == schema.Maybe_Absent { - l-- - } - if rn.protected.m == schema.Maybe_Absent { - l-- - } - return int64(l) + +func (rn *_List__Repr) Length() int64 { + return int64(len(rn.x)) } -func (_Signature__Repr) IsAbsent() bool { +func (_List__Repr) IsAbsent() bool { return false } -func (_Signature__Repr) IsNull() bool { +func (_List__Repr) IsNull() bool { return false } -func (_Signature__Repr) AsBool() (bool, error) { - return mixins.Map{TypeName: "dagjose.Signature.Repr"}.AsBool() +func (_List__Repr) AsBool() (bool, error) { + return mixins.List{TypeName: "dagjose.List.Repr"}.AsBool() } -func (_Signature__Repr) AsInt() (int64, error) { - return mixins.Map{TypeName: "dagjose.Signature.Repr"}.AsInt() +func (_List__Repr) AsInt() (int64, error) { + return mixins.List{TypeName: "dagjose.List.Repr"}.AsInt() } -func (_Signature__Repr) AsFloat() (float64, error) { - return mixins.Map{TypeName: "dagjose.Signature.Repr"}.AsFloat() +func (_List__Repr) AsFloat() (float64, error) { + return mixins.List{TypeName: "dagjose.List.Repr"}.AsFloat() } -func (_Signature__Repr) AsString() (string, error) { - return mixins.Map{TypeName: "dagjose.Signature.Repr"}.AsString() +func (_List__Repr) AsString() (string, error) { + return mixins.List{TypeName: "dagjose.List.Repr"}.AsString() } -func (_Signature__Repr) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "dagjose.Signature.Repr"}.AsBytes() +func (_List__Repr) AsBytes() ([]byte, error) { + return mixins.List{TypeName: "dagjose.List.Repr"}.AsBytes() } -func (_Signature__Repr) AsLink() (datamodel.Link, error) { - return mixins.Map{TypeName: "dagjose.Signature.Repr"}.AsLink() +func (_List__Repr) AsLink() (datamodel.Link, error) { + return mixins.List{TypeName: "dagjose.List.Repr"}.AsLink() } -func (_Signature__Repr) Prototype() datamodel.NodePrototype { - return _Signature__ReprPrototype{} +func (_List__Repr) Prototype() datamodel.NodePrototype { + return _List__ReprPrototype{} } -type _Signature__ReprPrototype struct{} +type _List__ReprPrototype struct{} -func (_Signature__ReprPrototype) NewBuilder() datamodel.NodeBuilder { - var nb _Signature__ReprBuilder +func (_List__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _List__ReprBuilder nb.Reset() return &nb } -type _Signature__ReprBuilder struct { - _Signature__ReprAssembler +type _List__ReprBuilder struct { + _List__ReprAssembler } -func (nb *_Signature__ReprBuilder) Build() datamodel.Node { +func (nb *_List__ReprBuilder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Signature__ReprBuilder) Reset() { - var w _Signature +func (nb *_List__ReprBuilder) Reset() { + var w _List var m schema.Maybe - *nb = _Signature__ReprBuilder{_Signature__ReprAssembler{w: &w, m: &m}} + *nb = _List__ReprBuilder{_List__ReprAssembler{w: &w, m: &m}} } -type _Signature__ReprAssembler struct { - w *_Signature +type _List__ReprAssembler struct { + w *_List m *schema.Maybe - state maState - s int - f int + state laState - cm schema.Maybe - ca_header _Any__ReprAssembler - ca_protected _Base64Url__ReprAssembler - ca_signature _Base64Url__ReprAssembler + cm schema.Maybe + va _Any__ReprAssembler } -func (na *_Signature__ReprAssembler) reset() { - na.state = maState_initial - na.s = 0 - na.ca_header.reset() - na.ca_protected.reset() - na.ca_signature.reset() +func (na *_List__ReprAssembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_List__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.BeginMap(0) } -func (na *_Signature__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, error) { +func (na *_List__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -7302,21 +12309,21 @@ func (na *_Signature__ReprAssembler) BeginMap(int64) (datamodel.MapAssembler, er panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") } *na.m = midvalue - if na.w == nil { - na.w = &_Signature{} + if sizeHint < 0 { + sizeHint = 0 + } + if sizeHint > 0 { + na.w.x = make([]_Any, 0, sizeHint) } return na, nil } -func (_Signature__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.MapAssembler{TypeName: "dagjose.Signature.Repr"}.BeginList(0) -} -func (na *_Signature__ReprAssembler) AssignNull() error { +func (na *_List__ReprAssembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{TypeName: "dagjose.Signature.Repr.Repr"}.AssignNull() + return mixins.ListAssembler{TypeName: "dagjose.List.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -7324,360 +12331,165 @@ func (na *_Signature__ReprAssembler) AssignNull() error { } panic("unreachable") } -func (_Signature__ReprAssembler) AssignBool(bool) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature.Repr"}.AssignBool(false) +func (_List__ReprAssembler) AssignBool(bool) error { + return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignBool(false) } -func (_Signature__ReprAssembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature.Repr"}.AssignInt(0) +func (_List__ReprAssembler) AssignInt(int64) error { + return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignInt(0) } -func (_Signature__ReprAssembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature.Repr"}.AssignFloat(0) +func (_List__ReprAssembler) AssignFloat(float64) error { + return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignFloat(0) } -func (_Signature__ReprAssembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature.Repr"}.AssignString("") +func (_List__ReprAssembler) AssignString(string) error { + return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignString("") } -func (_Signature__ReprAssembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature.Repr"}.AssignBytes(nil) +func (_List__ReprAssembler) AssignBytes([]byte) error { + return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignBytes(nil) } -func (_Signature__ReprAssembler) AssignLink(datamodel.Link) error { - return mixins.MapAssembler{TypeName: "dagjose.Signature.Repr"}.AssignLink(nil) +func (_List__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.ListAssembler{TypeName: "dagjose.List.Repr"}.AssignLink(nil) } -func (na *_Signature__ReprAssembler) AssignNode(v datamodel.Node) error { +func (na *_List__ReprAssembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Signature); ok { + if v2, ok := v.(*_List); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } - if na.w == nil { - na.w = v2 - *na.m = schema.Maybe_Value - return nil - } *na.w = *v2 *na.m = schema.Maybe_Value return nil } - if v.Kind() != datamodel.Kind_Map { - return datamodel.ErrWrongKind{TypeName: "dagjose.Signature.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} + if v.Kind() != datamodel.Kind_List { + return datamodel.ErrWrongKind{TypeName: "dagjose.List.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} } - itr := v.MapIterator() + itr := v.ListIterator() for !itr.Done() { - k, v, err := itr.Next() + _, v, err := itr.Next() if err != nil { return err } - if err := na.AssembleKey().AssignNode(k); err != nil { - return err - } if err := na.AssembleValue().AssignNode(v); err != nil { return err } } return na.Finish() } -func (_Signature__ReprAssembler) Prototype() datamodel.NodePrototype { - return _Signature__ReprPrototype{} -} -func (ma *_Signature__ReprAssembler) valueFinishTidy() bool { - switch ma.f { - case 0: - switch ma.w.header.m { - case schema.Maybe_Value: - ma.w.header.v = ma.ca_header.w - ma.state = maState_initial - return true - default: - return false - } - case 1: - switch ma.w.protected.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 2: - switch ma.cm { - case schema.Maybe_Value: - ma.cm = schema.Maybe_Absent - ma.state = maState_initial - return true - default: - return false - } - default: - panic("unreachable") - } +func (_List__ReprAssembler) Prototype() datamodel.NodePrototype { + return _List__ReprPrototype{} } -func (ma *_Signature__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { - switch ma.state { - case maState_initial: - // carry on - case maState_midKey: - panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") - case maState_expectValue: - panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") - } // if tidy success: carry on - case maState_finished: - panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") - } - switch k { - case "header": - if ma.s&fieldBit__Signature_Header != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Header_serial} - } - ma.s += fieldBit__Signature_Header - ma.state = maState_midValue - ma.f = 0 - ma.ca_header.w = ma.w.header.v - ma.ca_header.m = &ma.w.header.m - - return &ma.ca_header, nil - case "protected": - if ma.s&fieldBit__Signature_Protected != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Protected_serial} - } - ma.s += fieldBit__Signature_Protected - ma.state = maState_midValue - ma.f = 1 - ma.ca_protected.w = &ma.w.protected.v - ma.ca_protected.m = &ma.w.protected.m - - return &ma.ca_protected, nil - case "signature": - if ma.s&fieldBit__Signature_Signature != 0 { - return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Signature_serial} - } - ma.s += fieldBit__Signature_Signature - ma.state = maState_midValue - ma.f = 2 - ma.ca_signature.w = &ma.w.signature - ma.ca_signature.m = &ma.cm - return &ma.ca_signature, nil +func (la *_List__ReprAssembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true default: + return false } - return nil, schema.ErrInvalidKey{TypeName: "dagjose.Signature.Repr", Key: &_String{k}} } -func (ma *_Signature__ReprAssembler) AssembleKey() datamodel.NodeAssembler { - switch ma.state { - case maState_initial: +func (la *_List__ReprAssembler) AssembleValue() datamodel.NodeAssembler { + switch la.state { + case laState_initial: // carry on - case maState_midKey: - panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") - case maState_expectValue: - panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { - panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") } // if tidy success: carry on - case maState_finished: - panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") - } - ma.state = maState_midKey - return (*_Signature__ReprKeyAssembler)(ma) -} -func (ma *_Signature__ReprAssembler) AssembleValue() datamodel.NodeAssembler { - switch ma.state { - case maState_initial: - panic("invalid state: AssembleValue cannot be called when no key is primed") - case maState_midKey: - panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") - case maState_expectValue: - // carry on - case maState_midValue: - panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") - case maState_finished: + case laState_finished: panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") } - ma.state = maState_midValue - switch ma.f { - case 0: - ma.ca_header.w = ma.w.header.v - ma.ca_header.m = &ma.w.header.m - - return &ma.ca_header - case 1: - ma.ca_protected.w = &ma.w.protected.v - ma.ca_protected.m = &ma.w.protected.m - - return &ma.ca_protected - case 2: - ma.ca_signature.w = &ma.w.signature - ma.ca_signature.m = &ma.cm - return &ma.ca_signature - default: - panic("unreachable") - } + la.w.x = append(la.w.x, _Any{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va } -func (ma *_Signature__ReprAssembler) Finish() error { - switch ma.state { - case maState_initial: +func (la *_List__ReprAssembler) Finish() error { + switch la.state { + case laState_initial: // carry on - case maState_midKey: - panic("invalid state: Finish cannot be called when in the middle of assembling a key") - case maState_expectValue: - panic("invalid state: Finish cannot be called when expecting start of value assembly") - case maState_midValue: - if !ma.valueFinishTidy() { + case laState_midValue: + if !la.valueFinishTidy() { panic("invalid state: Finish cannot be called when in the middle of assembling a value") } // if tidy success: carry on - case maState_finished: + case laState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s&fieldBits__Signature_sufficient != fieldBits__Signature_sufficient { - err := schema.ErrMissingRequiredField{Missing: make([]string, 0)} - if ma.s&fieldBit__Signature_Signature == 0 { - err.Missing = append(err.Missing, "signature") - } - return err - } - ma.state = maState_finished - *ma.m = schema.Maybe_Value + la.state = laState_finished + *la.m = schema.Maybe_Value return nil } -func (ma *_Signature__ReprAssembler) KeyPrototype() datamodel.NodePrototype { - return _String__Prototype{} -} -func (ma *_Signature__ReprAssembler) ValuePrototype(k string) datamodel.NodePrototype { - panic("todo structbuilder mapassembler repr valueprototype") -} - -type _Signature__ReprKeyAssembler _Signature__ReprAssembler - -func (_Signature__ReprKeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.Signature.Repr.KeyAssembler"}.BeginMap(0) -} -func (_Signature__ReprKeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "dagjose.Signature.Repr.KeyAssembler"}.BeginList(0) -} -func (na *_Signature__ReprKeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.Repr.KeyAssembler"}.AssignNull() -} -func (_Signature__ReprKeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.Repr.KeyAssembler"}.AssignBool(false) -} -func (_Signature__ReprKeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.Repr.KeyAssembler"}.AssignInt(0) -} -func (_Signature__ReprKeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.Repr.KeyAssembler"}.AssignFloat(0) -} -func (ka *_Signature__ReprKeyAssembler) AssignString(k string) error { - if ka.state != maState_midKey { - panic("misuse: KeyAssembler held beyond its valid lifetime") - } - switch k { - case "header": - if ka.s&fieldBit__Signature_Header != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Header_serial} - } - ka.s += fieldBit__Signature_Header - ka.state = maState_expectValue - ka.f = 0 - return nil - case "protected": - if ka.s&fieldBit__Signature_Protected != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Protected_serial} - } - ka.s += fieldBit__Signature_Protected - ka.state = maState_expectValue - ka.f = 1 - return nil - case "signature": - if ka.s&fieldBit__Signature_Signature != 0 { - return datamodel.ErrRepeatedMapKey{Key: &fieldName__Signature_Signature_serial} - } - ka.s += fieldBit__Signature_Signature - ka.state = maState_expectValue - ka.f = 2 - return nil - } - return schema.ErrInvalidKey{TypeName: "dagjose.Signature.Repr", Key: &_String{k}} -} -func (_Signature__ReprKeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.Repr.KeyAssembler"}.AssignBytes(nil) -} -func (_Signature__ReprKeyAssembler) AssignLink(datamodel.Link) error { - return mixins.StringAssembler{TypeName: "dagjose.Signature.Repr.KeyAssembler"}.AssignLink(nil) -} -func (ka *_Signature__ReprKeyAssembler) AssignNode(v datamodel.Node) error { - if v2, err := v.AsString(); err != nil { - return err - } else { - return ka.AssignString(v2) - } -} -func (_Signature__ReprKeyAssembler) Prototype() datamodel.NodePrototype { - return _String__Prototype{} +func (la *_List__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype { + return _Any__ReprPrototype{} } -func (n *_Signatures) Lookup(idx int64) Signature { - if n.Length() <= idx { +func (n *_Map) Lookup(k String) Any { + v, exists := n.m[*k] + if !exists { return nil } - v := &n.x[idx] return v } -func (n *_Signatures) LookupMaybe(idx int64) MaybeSignature { - if n.Length() <= idx { - return nil +func (n *_Map) LookupMaybe(k String) MaybeAny { + v, exists := n.m[*k] + if !exists { + return &_Map__valueAbsent } - v := &n.x[idx] - return &_Signature__Maybe{ + return &_Any__Maybe{ m: schema.Maybe_Value, v: v, } } -var _Signatures__valueAbsent = _Signature__Maybe{m: schema.Maybe_Absent} +var _Map__valueAbsent = _Any__Maybe{m: schema.Maybe_Absent} -func (n Signatures) Iterator() *Signatures__Itr { - return &Signatures__Itr{n, 0} +func (n Map) Iterator() *Map__Itr { + return &Map__Itr{n, 0} } -type Signatures__Itr struct { - n Signatures +type Map__Itr struct { + n Map idx int } -func (itr *Signatures__Itr) Next() (idx int64, v Signature) { - if itr.idx >= len(itr.n.x) { - return -1, nil +func (itr *Map__Itr) Next() (k String, v Any) { + if itr.idx >= len(itr.n.t) { + return nil, nil } - idx = int64(itr.idx) - v = &itr.n.x[itr.idx] + x := &itr.n.t[itr.idx] + k = &x.k + v = &x.v itr.idx++ return } -func (itr *Signatures__Itr) Done() bool { - return itr.idx >= len(itr.n.x) +func (itr *Map__Itr) Done() bool { + return itr.idx >= len(itr.n.t) } -type _Signatures__Maybe struct { +type _Map__Maybe struct { m schema.Maybe - v _Signatures + v _Map } -type MaybeSignatures = *_Signatures__Maybe +type MaybeMap = *_Map__Maybe -func (m MaybeSignatures) IsNull() bool { +func (m MaybeMap) IsNull() bool { return m.m == schema.Maybe_Null } -func (m MaybeSignatures) IsAbsent() bool { +func (m MaybeMap) IsAbsent() bool { return m.m == schema.Maybe_Absent } -func (m MaybeSignatures) Exists() bool { +func (m MaybeMap) Exists() bool { return m.m == schema.Maybe_Value } -func (m MaybeSignatures) AsNode() datamodel.Node { +func (m MaybeMap) AsNode() datamodel.Node { switch m.m { case schema.Maybe_Absent: return datamodel.Absent @@ -7689,141 +12501,145 @@ func (m MaybeSignatures) AsNode() datamodel.Node { panic("unreachable") } } -func (m MaybeSignatures) Must() Signatures { +func (m MaybeMap) Must() Map { if !m.Exists() { panic("unbox of a maybe rejected") } return &m.v } -var _ datamodel.Node = (Signatures)(&_Signatures{}) -var _ schema.TypedNode = (Signatures)(&_Signatures{}) +var _ datamodel.Node = (Map)(&_Map{}) +var _ schema.TypedNode = (Map)(&_Map{}) -func (Signatures) Kind() datamodel.Kind { - return datamodel.Kind_List -} -func (Signatures) LookupByString(string) (datamodel.Node, error) { - return mixins.List{TypeName: "dagjose.Signatures"}.LookupByString("") +func (Map) Kind() datamodel.Kind { + return datamodel.Kind_Map } -func (n Signatures) LookupByNode(k datamodel.Node) (datamodel.Node, error) { - idx, err := k.AsInt() - if err != nil { - return nil, err +func (n Map) LookupByString(k string) (datamodel.Node, error) { + var k2 _String + if err := (_String__ReprPrototype{}).fromString(&k2, k); err != nil { + return nil, err // TODO wrap in some kind of ErrInvalidKey } - return n.LookupByIndex(idx) -} -func (n Signatures) LookupByIndex(idx int64) (datamodel.Node, error) { - if n.Length() <= idx { - return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)} + v, exists := n.m[k2] + if !exists { + return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(k)} } - v := &n.x[idx] return v, nil } -func (n Signatures) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - i, err := seg.Index() - if err != nil { - return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.Signatures", TroubleSegment: seg, Reason: err} +func (n Map) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + k2, ok := k.(String) + if !ok { + panic("todo invalid key type error") + // 'schema.ErrInvalidKey{TypeName:"dagjose.Map", Key:&_String{k}}' doesn't quite cut it: need room to explain the type, and it's not guaranteed k can be turned into a string at all } - return n.LookupByIndex(i) + v, exists := n.m[*k2] + if !exists { + return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(k2.String())} + } + return v, nil } -func (Signatures) MapIterator() datamodel.MapIterator { - return nil +func (Map) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.Map"}.LookupByIndex(0) +} +func (n Map) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) } -func (n Signatures) ListIterator() datamodel.ListIterator { - return &_Signatures__ListItr{n, 0} +func (n Map) MapIterator() datamodel.MapIterator { + return &_Map__MapItr{n, 0} } -type _Signatures__ListItr struct { - n Signatures +type _Map__MapItr struct { + n Map idx int } -func (itr *_Signatures__ListItr) Next() (idx int64, v datamodel.Node, _ error) { - if itr.idx >= len(itr.n.x) { - return -1, nil, datamodel.ErrIteratorOverread{} +func (itr *_Map__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) { + if itr.idx >= len(itr.n.t) { + return nil, nil, datamodel.ErrIteratorOverread{} } - idx = int64(itr.idx) - x := &itr.n.x[itr.idx] - v = x + x := &itr.n.t[itr.idx] + k = &x.k + v = &x.v itr.idx++ return } -func (itr *_Signatures__ListItr) Done() bool { - return itr.idx >= len(itr.n.x) +func (itr *_Map__MapItr) Done() bool { + return itr.idx >= len(itr.n.t) } -func (n Signatures) Length() int64 { - return int64(len(n.x)) +func (Map) ListIterator() datamodel.ListIterator { + return nil +} +func (n Map) Length() int64 { + return int64(len(n.t)) } -func (Signatures) IsAbsent() bool { +func (Map) IsAbsent() bool { return false } -func (Signatures) IsNull() bool { +func (Map) IsNull() bool { return false } -func (Signatures) AsBool() (bool, error) { - return mixins.List{TypeName: "dagjose.Signatures"}.AsBool() +func (Map) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.Map"}.AsBool() } -func (Signatures) AsInt() (int64, error) { - return mixins.List{TypeName: "dagjose.Signatures"}.AsInt() +func (Map) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.Map"}.AsInt() } -func (Signatures) AsFloat() (float64, error) { - return mixins.List{TypeName: "dagjose.Signatures"}.AsFloat() +func (Map) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.Map"}.AsFloat() } -func (Signatures) AsString() (string, error) { - return mixins.List{TypeName: "dagjose.Signatures"}.AsString() +func (Map) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.Map"}.AsString() } -func (Signatures) AsBytes() ([]byte, error) { - return mixins.List{TypeName: "dagjose.Signatures"}.AsBytes() +func (Map) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.Map"}.AsBytes() } -func (Signatures) AsLink() (datamodel.Link, error) { - return mixins.List{TypeName: "dagjose.Signatures"}.AsLink() +func (Map) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.Map"}.AsLink() } -func (Signatures) Prototype() datamodel.NodePrototype { - return _Signatures__Prototype{} +func (Map) Prototype() datamodel.NodePrototype { + return _Map__Prototype{} } -type _Signatures__Prototype struct{} +type _Map__Prototype struct{} -func (_Signatures__Prototype) NewBuilder() datamodel.NodeBuilder { - var nb _Signatures__Builder +func (_Map__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _Map__Builder nb.Reset() return &nb } -type _Signatures__Builder struct { - _Signatures__Assembler +type _Map__Builder struct { + _Map__Assembler } -func (nb *_Signatures__Builder) Build() datamodel.Node { +func (nb *_Map__Builder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Signatures__Builder) Reset() { - var w _Signatures +func (nb *_Map__Builder) Reset() { + var w _Map var m schema.Maybe - *nb = _Signatures__Builder{_Signatures__Assembler{w: &w, m: &m}} + *nb = _Map__Builder{_Map__Assembler{w: &w, m: &m}} } -type _Signatures__Assembler struct { - w *_Signatures +type _Map__Assembler struct { + w *_Map m *schema.Maybe - state laState + state maState cm schema.Maybe - va _Signature__Assembler + ka _String__Assembler + va _Any__Assembler } -func (na *_Signatures__Assembler) reset() { - na.state = laState_initial +func (na *_Map__Assembler) reset() { + na.state = maState_initial + na.ka.reset() na.va.reset() } -func (_Signatures__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.ListAssembler{TypeName: "dagjose.Signatures"}.BeginMap(0) -} -func (na *_Signatures__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { +func (na *_Map__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -7834,18 +12650,20 @@ func (na *_Signatures__Assembler) BeginList(sizeHint int64) (datamodel.ListAssem if sizeHint < 0 { sizeHint = 0 } - if sizeHint > 0 { - na.w.x = make([]_Signature, 0, sizeHint) - } + na.w.m = make(map[_String]*_Any, sizeHint) + na.w.t = make([]_Map__entry, 0, sizeHint) return na, nil } -func (na *_Signatures__Assembler) AssignNull() error { +func (_Map__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.Map"}.BeginList(0) +} +func (na *_Map__Assembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.ListAssembler{TypeName: "dagjose.Signatures"}.AssignNull() + return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -7853,29 +12671,29 @@ func (na *_Signatures__Assembler) AssignNull() error { } panic("unreachable") } -func (_Signatures__Assembler) AssignBool(bool) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures"}.AssignBool(false) +func (_Map__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignBool(false) } -func (_Signatures__Assembler) AssignInt(int64) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures"}.AssignInt(0) +func (_Map__Assembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignInt(0) } -func (_Signatures__Assembler) AssignFloat(float64) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures"}.AssignFloat(0) +func (_Map__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignFloat(0) } -func (_Signatures__Assembler) AssignString(string) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures"}.AssignString("") +func (_Map__Assembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignString("") } -func (_Signatures__Assembler) AssignBytes([]byte) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures"}.AssignBytes(nil) +func (_Map__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignBytes(nil) } -func (_Signatures__Assembler) AssignLink(datamodel.Link) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures"}.AssignLink(nil) +func (_Map__Assembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.Map"}.AssignLink(nil) } -func (na *_Signatures__Assembler) AssignNode(v datamodel.Node) error { +func (na *_Map__Assembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Signatures); ok { + if v2, ok := v.(*_Map); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -7886,202 +12704,276 @@ func (na *_Signatures__Assembler) AssignNode(v datamodel.Node) error { *na.m = schema.Maybe_Value return nil } - if v.Kind() != datamodel.Kind_List { - return datamodel.ErrWrongKind{TypeName: "dagjose.Signatures", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} + if v.Kind() != datamodel.Kind_Map { + return datamodel.ErrWrongKind{TypeName: "dagjose.Map", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} } - itr := v.ListIterator() + itr := v.MapIterator() for !itr.Done() { - _, v, err := itr.Next() + k, v, err := itr.Next() if err != nil { return err } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } if err := na.AssembleValue().AssignNode(v); err != nil { return err } } return na.Finish() } -func (_Signatures__Assembler) Prototype() datamodel.NodePrototype { - return _Signatures__Prototype{} +func (_Map__Assembler) Prototype() datamodel.NodePrototype { + return _Map__Prototype{} } -func (la *_Signatures__Assembler) valueFinishTidy() bool { - switch la.cm { +func (ma *_Map__Assembler) keyFinishTidy() bool { + switch ma.cm { case schema.Maybe_Value: - la.va.w = nil - la.cm = schema.Maybe_Absent - la.state = laState_initial - la.va.reset() + ma.ka.w = nil + tz := &ma.w.t[len(ma.w.t)-1] + ma.cm = schema.Maybe_Absent + ma.state = maState_expectValue + ma.w.m[tz.k] = &tz.v + ma.va.w = &tz.v + ma.va.m = &ma.cm + ma.ka.reset() return true default: return false } } -func (la *_Signatures__Assembler) AssembleValue() datamodel.NodeAssembler { - switch la.state { - case laState_initial: +func (ma *_Map__Assembler) valueFinishTidy() bool { + switch ma.cm { + case schema.Maybe_Value: + ma.va.w = nil + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + ma.va.reset() + return true + default: + return false + } +} +func (ma *_Map__Assembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: // carry on - case laState_midValue: - if !la.valueFinishTidy() { - panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") } // if tidy success: carry on - case laState_finished: - panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") } - la.w.x = append(la.w.x, _Signature{}) - la.state = laState_midValue - row := &la.w.x[len(la.w.x)-1] - la.va.w = row - la.va.m = &la.cm - return &la.va + + var k2 _String + if err := (_String__ReprPrototype{}).fromString(&k2, k); err != nil { + return nil, err // TODO wrap in some kind of ErrInvalidKey + } + if _, exists := ma.w.m[k2]; exists { + return nil, datamodel.ErrRepeatedMapKey{Key: &k2} + } + ma.w.t = append(ma.w.t, _Map__entry{k: k2}) + tz := &ma.w.t[len(ma.w.t)-1] + ma.state = maState_midValue + + ma.w.m[k2] = &tz.v + ma.va.w = &tz.v + ma.va.m = &ma.cm + return &ma.va, nil } -func (la *_Signatures__Assembler) Finish() error { - switch la.state { - case laState_initial: +func (ma *_Map__Assembler) AssembleKey() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: // carry on - case laState_midValue: - if !la.valueFinishTidy() { + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.w.t = append(ma.w.t, _Map__entry{}) + ma.state = maState_midKey + ma.ka.m = &ma.cm + ma.ka.w = &ma.w.t[len(ma.w.t)-1].k + return &ma.ka +} +func (ma *_Map__Assembler) AssembleValue() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + if !ma.keyFinishTidy() { + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + } // if tidy success: carry on + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + return &ma.va +} +func (ma *_Map__Assembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { panic("invalid state: Finish cannot be called when in the middle of assembling a value") } // if tidy success: carry on - case laState_finished: + case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - la.state = laState_finished - *la.m = schema.Maybe_Value + ma.state = maState_finished + *ma.m = schema.Maybe_Value return nil } -func (la *_Signatures__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype { - return _Signature__Prototype{} +func (ma *_Map__Assembler) KeyPrototype() datamodel.NodePrototype { + return _String__Prototype{} +} +func (ma *_Map__Assembler) ValuePrototype(_ string) datamodel.NodePrototype { + return _Any__Prototype{} } -func (Signatures) Type() schema.Type { +func (Map) Type() schema.Type { return nil /*TODO:typelit*/ } -func (n Signatures) Representation() datamodel.Node { - return (*_Signatures__Repr)(n) +func (n Map) Representation() datamodel.Node { + return (*_Map__Repr)(n) } -type _Signatures__Repr _Signatures +type _Map__Repr _Map -var _ datamodel.Node = &_Signatures__Repr{} +var _ datamodel.Node = &_Map__Repr{} -func (_Signatures__Repr) Kind() datamodel.Kind { - return datamodel.Kind_List -} -func (_Signatures__Repr) LookupByString(string) (datamodel.Node, error) { - return mixins.List{TypeName: "dagjose.Signatures.Repr"}.LookupByString("") +func (_Map__Repr) Kind() datamodel.Kind { + return datamodel.Kind_Map } -func (nr *_Signatures__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) { - v, err := (Signatures)(nr).LookupByNode(k) +func (nr *_Map__Repr) LookupByString(k string) (datamodel.Node, error) { + v, err := (Map)(nr).LookupByString(k) if err != nil || v == datamodel.Null { return v, err } - return v.(Signature).Representation(), nil + return v.(Any).Representation(), nil } -func (nr *_Signatures__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { - v, err := (Signatures)(nr).LookupByIndex(idx) +func (nr *_Map__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) { + v, err := (Map)(nr).LookupByNode(k) if err != nil || v == datamodel.Null { return v, err } - return v.(Signature).Representation(), nil + return v.(Any).Representation(), nil } -func (n _Signatures__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { - i, err := seg.Index() - if err != nil { - return nil, datamodel.ErrInvalidSegmentForList{TypeName: "dagjose.Signatures.Repr", TroubleSegment: seg, Reason: err} - } - return n.LookupByIndex(i) +func (_Map__Repr) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Map{TypeName: "dagjose.Map.Repr"}.LookupByIndex(0) } -func (_Signatures__Repr) MapIterator() datamodel.MapIterator { - return nil +func (n _Map__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return n.LookupByString(seg.String()) } -func (nr *_Signatures__Repr) ListIterator() datamodel.ListIterator { - return &_Signatures__ReprListItr{(Signatures)(nr), 0} +func (nr *_Map__Repr) MapIterator() datamodel.MapIterator { + return &_Map__ReprMapItr{(Map)(nr), 0} } -type _Signatures__ReprListItr _Signatures__ListItr +type _Map__ReprMapItr _Map__MapItr -func (itr *_Signatures__ReprListItr) Next() (idx int64, v datamodel.Node, err error) { - idx, v, err = (*_Signatures__ListItr)(itr).Next() +func (itr *_Map__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, err error) { + k, v, err = (*_Map__MapItr)(itr).Next() if err != nil || v == datamodel.Null { return } - return idx, v.(Signature).Representation(), nil + return k, v.(Any).Representation(), nil } -func (itr *_Signatures__ReprListItr) Done() bool { - return (*_Signatures__ListItr)(itr).Done() +func (itr *_Map__ReprMapItr) Done() bool { + return (*_Map__MapItr)(itr).Done() } -func (rn *_Signatures__Repr) Length() int64 { - return int64(len(rn.x)) +func (_Map__Repr) ListIterator() datamodel.ListIterator { + return nil +} +func (rn *_Map__Repr) Length() int64 { + return int64(len(rn.t)) } -func (_Signatures__Repr) IsAbsent() bool { +func (_Map__Repr) IsAbsent() bool { return false } -func (_Signatures__Repr) IsNull() bool { +func (_Map__Repr) IsNull() bool { return false } -func (_Signatures__Repr) AsBool() (bool, error) { - return mixins.List{TypeName: "dagjose.Signatures.Repr"}.AsBool() +func (_Map__Repr) AsBool() (bool, error) { + return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsBool() } -func (_Signatures__Repr) AsInt() (int64, error) { - return mixins.List{TypeName: "dagjose.Signatures.Repr"}.AsInt() +func (_Map__Repr) AsInt() (int64, error) { + return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsInt() } -func (_Signatures__Repr) AsFloat() (float64, error) { - return mixins.List{TypeName: "dagjose.Signatures.Repr"}.AsFloat() +func (_Map__Repr) AsFloat() (float64, error) { + return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsFloat() } -func (_Signatures__Repr) AsString() (string, error) { - return mixins.List{TypeName: "dagjose.Signatures.Repr"}.AsString() +func (_Map__Repr) AsString() (string, error) { + return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsString() } -func (_Signatures__Repr) AsBytes() ([]byte, error) { - return mixins.List{TypeName: "dagjose.Signatures.Repr"}.AsBytes() +func (_Map__Repr) AsBytes() ([]byte, error) { + return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsBytes() } -func (_Signatures__Repr) AsLink() (datamodel.Link, error) { - return mixins.List{TypeName: "dagjose.Signatures.Repr"}.AsLink() +func (_Map__Repr) AsLink() (datamodel.Link, error) { + return mixins.Map{TypeName: "dagjose.Map.Repr"}.AsLink() } -func (_Signatures__Repr) Prototype() datamodel.NodePrototype { - return _Signatures__ReprPrototype{} +func (_Map__Repr) Prototype() datamodel.NodePrototype { + return _Map__ReprPrototype{} } -type _Signatures__ReprPrototype struct{} +type _Map__ReprPrototype struct{} -func (_Signatures__ReprPrototype) NewBuilder() datamodel.NodeBuilder { - var nb _Signatures__ReprBuilder +func (_Map__ReprPrototype) NewBuilder() datamodel.NodeBuilder { + var nb _Map__ReprBuilder nb.Reset() return &nb } -type _Signatures__ReprBuilder struct { - _Signatures__ReprAssembler +type _Map__ReprBuilder struct { + _Map__ReprAssembler } -func (nb *_Signatures__ReprBuilder) Build() datamodel.Node { +func (nb *_Map__ReprBuilder) Build() datamodel.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") } return nb.w } -func (nb *_Signatures__ReprBuilder) Reset() { - var w _Signatures +func (nb *_Map__ReprBuilder) Reset() { + var w _Map var m schema.Maybe - *nb = _Signatures__ReprBuilder{_Signatures__ReprAssembler{w: &w, m: &m}} + *nb = _Map__ReprBuilder{_Map__ReprAssembler{w: &w, m: &m}} } -type _Signatures__ReprAssembler struct { - w *_Signatures +type _Map__ReprAssembler struct { + w *_Map m *schema.Maybe - state laState + state maState cm schema.Maybe - va _Signature__ReprAssembler + ka _String__ReprAssembler + va _Any__ReprAssembler } -func (na *_Signatures__ReprAssembler) reset() { - na.state = laState_initial +func (na *_Map__ReprAssembler) reset() { + na.state = maState_initial + na.ka.reset() na.va.reset() } -func (_Signatures__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { - return mixins.ListAssembler{TypeName: "dagjose.Signatures.Repr"}.BeginMap(0) -} -func (na *_Signatures__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { +func (na *_Map__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -8092,18 +12984,20 @@ func (na *_Signatures__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListA if sizeHint < 0 { sizeHint = 0 } - if sizeHint > 0 { - na.w.x = make([]_Signature, 0, sizeHint) - } + na.w.m = make(map[_String]*_Any, sizeHint) + na.w.t = make([]_Map__entry, 0, sizeHint) return na, nil } -func (na *_Signatures__ReprAssembler) AssignNull() error { +func (_Map__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.BeginList(0) +} +func (na *_Map__ReprAssembler) AssignNull() error { switch *na.m { case allowNull: *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.ListAssembler{TypeName: "dagjose.Signatures.Repr.Repr"}.AssignNull() + return mixins.MapAssembler{TypeName: "dagjose.Map.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -8111,29 +13005,29 @@ func (na *_Signatures__ReprAssembler) AssignNull() error { } panic("unreachable") } -func (_Signatures__ReprAssembler) AssignBool(bool) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures.Repr"}.AssignBool(false) +func (_Map__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignBool(false) } -func (_Signatures__ReprAssembler) AssignInt(int64) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures.Repr"}.AssignInt(0) +func (_Map__ReprAssembler) AssignInt(int64) error { + return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignInt(0) } -func (_Signatures__ReprAssembler) AssignFloat(float64) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures.Repr"}.AssignFloat(0) +func (_Map__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignFloat(0) } -func (_Signatures__ReprAssembler) AssignString(string) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures.Repr"}.AssignString("") +func (_Map__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignString("") } -func (_Signatures__ReprAssembler) AssignBytes([]byte) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures.Repr"}.AssignBytes(nil) +func (_Map__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignBytes(nil) } -func (_Signatures__ReprAssembler) AssignLink(datamodel.Link) error { - return mixins.ListAssembler{TypeName: "dagjose.Signatures.Repr"}.AssignLink(nil) +func (_Map__ReprAssembler) AssignLink(datamodel.Link) error { + return mixins.MapAssembler{TypeName: "dagjose.Map.Repr"}.AssignLink(nil) } -func (na *_Signatures__ReprAssembler) AssignNode(v datamodel.Node) error { +func (na *_Map__ReprAssembler) AssignNode(v datamodel.Node) error { if v.IsNull() { return na.AssignNull() } - if v2, ok := v.(*_Signatures); ok { + if v2, ok := v.(*_Map); ok { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") @@ -8144,71 +13038,150 @@ func (na *_Signatures__ReprAssembler) AssignNode(v datamodel.Node) error { *na.m = schema.Maybe_Value return nil } - if v.Kind() != datamodel.Kind_List { - return datamodel.ErrWrongKind{TypeName: "dagjose.Signatures.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()} + if v.Kind() != datamodel.Kind_Map { + return datamodel.ErrWrongKind{TypeName: "dagjose.Map.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()} } - itr := v.ListIterator() + itr := v.MapIterator() for !itr.Done() { - _, v, err := itr.Next() + k, v, err := itr.Next() if err != nil { return err } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } if err := na.AssembleValue().AssignNode(v); err != nil { return err } } return na.Finish() } -func (_Signatures__ReprAssembler) Prototype() datamodel.NodePrototype { - return _Signatures__ReprPrototype{} +func (_Map__ReprAssembler) Prototype() datamodel.NodePrototype { + return _Map__ReprPrototype{} +} +func (ma *_Map__ReprAssembler) keyFinishTidy() bool { + switch ma.cm { + case schema.Maybe_Value: + ma.ka.w = nil + tz := &ma.w.t[len(ma.w.t)-1] + ma.cm = schema.Maybe_Absent + ma.state = maState_expectValue + ma.w.m[tz.k] = &tz.v + ma.va.w = &tz.v + ma.va.m = &ma.cm + ma.ka.reset() + return true + default: + return false + } } -func (la *_Signatures__ReprAssembler) valueFinishTidy() bool { - switch la.cm { +func (ma *_Map__ReprAssembler) valueFinishTidy() bool { + switch ma.cm { case schema.Maybe_Value: - la.va.w = nil - la.cm = schema.Maybe_Absent - la.state = laState_initial - la.va.reset() + ma.va.w = nil + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + ma.va.reset() return true default: return false } } -func (la *_Signatures__ReprAssembler) AssembleValue() datamodel.NodeAssembler { - switch la.state { - case laState_initial: +func (ma *_Map__ReprAssembler) AssembleEntry(k string) (datamodel.NodeAssembler, error) { + switch ma.state { + case maState_initial: // carry on - case laState_midValue: - if !la.valueFinishTidy() { - panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") } // if tidy success: carry on - case laState_finished: + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + + var k2 _String + if err := (_String__ReprPrototype{}).fromString(&k2, k); err != nil { + return nil, err // TODO wrap in some kind of ErrInvalidKey + } + if _, exists := ma.w.m[k2]; exists { + return nil, datamodel.ErrRepeatedMapKey{Key: &k2} + } + ma.w.t = append(ma.w.t, _Map__entry{k: k2}) + tz := &ma.w.t[len(ma.w.t)-1] + ma.state = maState_midValue + + ma.w.m[k2] = &tz.v + ma.va.w = &tz.v + ma.va.m = &ma.cm + return &ma.va, nil +} +func (ma *_Map__ReprAssembler) AssembleKey() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.w.t = append(ma.w.t, _Map__entry{}) + ma.state = maState_midKey + ma.ka.m = &ma.cm + ma.ka.w = &ma.w.t[len(ma.w.t)-1].k + return &ma.ka +} +func (ma *_Map__ReprAssembler) AssembleValue() datamodel.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + if !ma.keyFinishTidy() { + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + } // if tidy success: carry on + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") } - la.w.x = append(la.w.x, _Signature{}) - la.state = laState_midValue - row := &la.w.x[len(la.w.x)-1] - la.va.w = row - la.va.m = &la.cm - return &la.va + ma.state = maState_midValue + return &ma.va } -func (la *_Signatures__ReprAssembler) Finish() error { - switch la.state { - case laState_initial: +func (ma *_Map__ReprAssembler) Finish() error { + switch ma.state { + case maState_initial: // carry on - case laState_midValue: - if !la.valueFinishTidy() { + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { panic("invalid state: Finish cannot be called when in the middle of assembling a value") } // if tidy success: carry on - case laState_finished: + case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - la.state = laState_finished - *la.m = schema.Maybe_Value + ma.state = maState_finished + *ma.m = schema.Maybe_Value return nil } -func (la *_Signatures__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype { - return _Signature__ReprPrototype{} +func (ma *_Map__ReprAssembler) KeyPrototype() datamodel.NodePrototype { + return _String__ReprPrototype{} +} +func (ma *_Map__ReprAssembler) ValuePrototype(_ string) datamodel.NodePrototype { + return _Any__ReprPrototype{} } func (n String) String() string { diff --git a/dagjose/ipldsch_types.go b/dagjose/ipldsch_types.go index a88372a..c3c1a58 100644 --- a/dagjose/ipldsch_types.go +++ b/dagjose/ipldsch_types.go @@ -20,34 +20,46 @@ var _ datamodel.Node = nil // suppress errors when this dependency is not refere var Type typeSlab type typeSlab struct { - Any _Any__Prototype - Any__Repr _Any__ReprPrototype - Base64Url _Base64Url__Prototype - Base64Url__Repr _Base64Url__ReprPrototype - Bytes _Bytes__Prototype - Bytes__Repr _Bytes__ReprPrototype - Float _Float__Prototype - Float__Repr _Float__ReprPrototype - Int _Int__Prototype - Int__Repr _Int__ReprPrototype - JOSE _JOSE__Prototype - JOSE__Repr _JOSE__ReprPrototype - Link _Link__Prototype - Link__Repr _Link__ReprPrototype - List _List__Prototype - List__Repr _List__ReprPrototype - Map _Map__Prototype - Map__Repr _Map__ReprPrototype - Recipient _Recipient__Prototype - Recipient__Repr _Recipient__ReprPrototype - Recipients _Recipients__Prototype - Recipients__Repr _Recipients__ReprPrototype - Signature _Signature__Prototype - Signature__Repr _Signature__ReprPrototype - Signatures _Signatures__Prototype - Signatures__Repr _Signatures__ReprPrototype - String _String__Prototype - String__Repr _String__ReprPrototype + Any _Any__Prototype + Any__Repr _Any__ReprPrototype + Base64Url _Base64Url__Prototype + Base64Url__Repr _Base64Url__ReprPrototype + Bytes _Bytes__Prototype + Bytes__Repr _Bytes__ReprPrototype + DecodedJOSE _DecodedJOSE__Prototype + DecodedJOSE__Repr _DecodedJOSE__ReprPrototype + DecodedRecipient _DecodedRecipient__Prototype + DecodedRecipient__Repr _DecodedRecipient__ReprPrototype + DecodedRecipients _DecodedRecipients__Prototype + DecodedRecipients__Repr _DecodedRecipients__ReprPrototype + DecodedSignature _DecodedSignature__Prototype + DecodedSignature__Repr _DecodedSignature__ReprPrototype + DecodedSignatures _DecodedSignatures__Prototype + DecodedSignatures__Repr _DecodedSignatures__ReprPrototype + EncodedJOSE _EncodedJOSE__Prototype + EncodedJOSE__Repr _EncodedJOSE__ReprPrototype + EncodedRecipient _EncodedRecipient__Prototype + EncodedRecipient__Repr _EncodedRecipient__ReprPrototype + EncodedRecipients _EncodedRecipients__Prototype + EncodedRecipients__Repr _EncodedRecipients__ReprPrototype + EncodedSignature _EncodedSignature__Prototype + EncodedSignature__Repr _EncodedSignature__ReprPrototype + EncodedSignatures _EncodedSignatures__Prototype + EncodedSignatures__Repr _EncodedSignatures__ReprPrototype + Float _Float__Prototype + Float__Repr _Float__ReprPrototype + Int _Int__Prototype + Int__Repr _Int__ReprPrototype + Link _Link__Prototype + Link__Repr _Link__ReprPrototype + List _List__Prototype + List__Repr _List__ReprPrototype + Map _Map__Prototype + Map__Repr _Map__ReprPrototype + Raw _Raw__Prototype + Raw__Repr _Raw__ReprPrototype + String _String__Prototype + String__Repr _String__ReprPrototype } // --- type definitions follow --- @@ -77,29 +89,98 @@ type _Base64Url struct{ x string } type Bytes = *_Bytes type _Bytes struct{ x []byte } -// Float matches the IPLD Schema type "Float". It has float kind. -type Float = *_Float -type _Float struct{ x float64 } - -// Int matches the IPLD Schema type "Int". It has int kind. -type Int = *_Int -type _Int struct{ x int64 } - -// JOSE matches the IPLD Schema type "JOSE". It has struct type-kind, and may be interrogated like map kind. -type JOSE = *_JOSE -type _JOSE struct { +// DecodedJOSE matches the IPLD Schema type "DecodedJOSE". It has struct type-kind, and may be interrogated like map kind. +type DecodedJOSE = *_DecodedJOSE +type _DecodedJOSE struct { aad _Base64Url__Maybe ciphertext _Base64Url__Maybe iv _Base64Url__Maybe link _Link__Maybe payload _Base64Url__Maybe protected _Base64Url__Maybe - recipients _Recipients__Maybe - signatures _Signatures__Maybe + recipients _DecodedRecipients__Maybe + signatures _DecodedSignatures__Maybe tag _Base64Url__Maybe unprotected _Any__Maybe } +// DecodedRecipient matches the IPLD Schema type "DecodedRecipient". It has struct type-kind, and may be interrogated like map kind. +type DecodedRecipient = *_DecodedRecipient +type _DecodedRecipient struct { + header _Any__Maybe + encrypted_key _Base64Url__Maybe +} + +// DecodedRecipients matches the IPLD Schema type "DecodedRecipients". It has list kind. +type DecodedRecipients = *_DecodedRecipients +type _DecodedRecipients struct { + x []_DecodedRecipient +} + +// DecodedSignature matches the IPLD Schema type "DecodedSignature". It has struct type-kind, and may be interrogated like map kind. +type DecodedSignature = *_DecodedSignature +type _DecodedSignature struct { + header _Any__Maybe + protected _Base64Url__Maybe + signature _Base64Url +} + +// DecodedSignatures matches the IPLD Schema type "DecodedSignatures". It has list kind. +type DecodedSignatures = *_DecodedSignatures +type _DecodedSignatures struct { + x []_DecodedSignature +} + +// EncodedJOSE matches the IPLD Schema type "EncodedJOSE". It has struct type-kind, and may be interrogated like map kind. +type EncodedJOSE = *_EncodedJOSE +type _EncodedJOSE struct { + aad _Raw__Maybe + ciphertext _Raw__Maybe + iv _Raw__Maybe + link _Link__Maybe + payload _Raw__Maybe + protected _Raw__Maybe + recipients _EncodedRecipients__Maybe + signatures _EncodedSignatures__Maybe + tag _Raw__Maybe + unprotected _Any__Maybe +} + +// EncodedRecipient matches the IPLD Schema type "EncodedRecipient". It has struct type-kind, and may be interrogated like map kind. +type EncodedRecipient = *_EncodedRecipient +type _EncodedRecipient struct { + header _Any__Maybe + encrypted_key _Raw__Maybe +} + +// EncodedRecipients matches the IPLD Schema type "EncodedRecipients". It has list kind. +type EncodedRecipients = *_EncodedRecipients +type _EncodedRecipients struct { + x []_EncodedRecipient +} + +// EncodedSignature matches the IPLD Schema type "EncodedSignature". It has struct type-kind, and may be interrogated like map kind. +type EncodedSignature = *_EncodedSignature +type _EncodedSignature struct { + header _Any__Maybe + protected _Raw__Maybe + signature _Raw +} + +// EncodedSignatures matches the IPLD Schema type "EncodedSignatures". It has list kind. +type EncodedSignatures = *_EncodedSignatures +type _EncodedSignatures struct { + x []_EncodedSignature +} + +// Float matches the IPLD Schema type "Float". It has float kind. +type Float = *_Float +type _Float struct{ x float64 } + +// Int matches the IPLD Schema type "Int". It has int kind. +type Int = *_Int +type _Int struct{ x int64 } + // Link matches the IPLD Schema type "Link". It has link kind. type Link = *_Link type _Link struct{ x datamodel.Link } @@ -121,32 +202,9 @@ type _Map__entry struct { v _Any } -// Recipient matches the IPLD Schema type "Recipient". It has struct type-kind, and may be interrogated like map kind. -type Recipient = *_Recipient -type _Recipient struct { - header _Any__Maybe - encrypted_key _Base64Url__Maybe -} - -// Recipients matches the IPLD Schema type "Recipients". It has list kind. -type Recipients = *_Recipients -type _Recipients struct { - x []_Recipient -} - -// Signature matches the IPLD Schema type "Signature". It has struct type-kind, and may be interrogated like map kind. -type Signature = *_Signature -type _Signature struct { - header _Any__Maybe - protected _Base64Url__Maybe - signature _Base64Url -} - -// Signatures matches the IPLD Schema type "Signatures". It has list kind. -type Signatures = *_Signatures -type _Signatures struct { - x []_Signature -} +// Raw matches the IPLD Schema type "Raw". It has bytes kind. +type Raw = *_Raw +type _Raw struct{ x []byte } // String matches the IPLD Schema type "String". It has string kind. type String = *_String diff --git a/dagjose/jose_logic.go b/dagjose/jose_logic.go index 295c994..9c83019 100644 --- a/dagjose/jose_logic.go +++ b/dagjose/jose_logic.go @@ -10,32 +10,10 @@ import ( "github.com/ipld/go-ipld-prime/schema" ) -func (n Base64Url) String() string { - return encodeBase64Url(n.x) -} - -func (_Base64Url__Prototype) fromString(w *_Base64Url, v string) error { - base64Url, err := Type.Base64Url.FromString(v) - if err != nil { - return err - } - *w = *base64Url - return nil -} - -func (_Base64Url__Prototype) FromString(v string) (Base64Url, error) { - decoded, err := decodeBase64Url(v) - if err != nil { - return nil, err - } - return &_Base64Url{decoded}, nil -} - type _Base64Url__Maybe struct { m schema.Maybe v _Base64Url } - type MaybeBase64Url = *_Base64Url__Maybe func (m MaybeBase64Url) IsNull() bool { @@ -109,10 +87,10 @@ func (Base64Url) AsFloat() (float64, error) { return mixins.String{TypeName: "dagjose.Base64Url"}.AsFloat() } func (n Base64Url) AsString() (string, error) { - return n.x, nil + return encodeBase64Url([]byte(n.x)), nil } -func (Base64Url) AsBytes() ([]byte, error) { - return mixins.String{TypeName: "dagjose.Base64Url"}.AsBytes() +func (n Base64Url) AsBytes() ([]byte, error) { + return []byte(n.x), nil } func (Base64Url) AsLink() (datamodel.Link, error) { return mixins.String{TypeName: "dagjose.Base64Url"}.AsLink() @@ -183,13 +161,13 @@ func (na *_Base64Url__Assembler) AssignString(v string) error { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") } - decoded, err := decodeBase64Url(v) - if err != nil { + if decodedBytes, err := decodeBase64Url(v); err != nil { return err + } else { + na.w.x = string(decodedBytes) + *na.m = schema.Maybe_Value + return nil } - na.w.x = decoded - *na.m = schema.Maybe_Value - return nil } func (na *_Base64Url__Assembler) AssignBytes(v []byte) error { switch *na.m { @@ -217,6 +195,13 @@ func (na *_Base64Url__Assembler) AssignNode(v datamodel.Node) error { return nil } if v2, err := v.AsString(); err != nil { + if e, wrongKind := err.(datamodel.ErrWrongKind); wrongKind && (e.ActualKind == datamodel.Kind_Bytes) { + if v2, err := v.AsBytes(); err != nil { + return err + } else { + return na.AssignBytes(v2) + } + } return err } else { return na.AssignString(v2) @@ -226,7 +211,7 @@ func (_Base64Url__Assembler) Prototype() datamodel.NodePrototype { return _Base64Url__Prototype{} } func (Base64Url) Type() schema.Type { - return nil /*TODO:typelit*/ + return nil } func (n Base64Url) Representation() datamodel.Node { return (*_Base64Url__Repr)(n) @@ -247,11 +232,225 @@ func (_Base64Url__Prototype) Link(n Base64Url) (Link, error) { return &_Link{cidlink.Link{Cid: c}}, nil } -func encodeBase64Url(decoded string) string { - return base64.RawURLEncoding.EncodeToString([]byte(decoded)) +type _Raw__Maybe struct { + m schema.Maybe + v _Raw +} +type MaybeRaw = *_Raw__Maybe + +func (m MaybeRaw) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeRaw) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeRaw) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeRaw) AsNode() datamodel.Node { + switch m.m { + case schema.Maybe_Absent: + return datamodel.Absent + case schema.Maybe_Null: + return datamodel.Null + case schema.Maybe_Value: + return &m.v + default: + panic("unreachable") + } +} +func (m MaybeRaw) Must() Raw { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return &m.v +} + +var _ datamodel.Node = (Raw)(&_Raw{}) +var _ schema.TypedNode = (Raw)(&_Raw{}) + +func (Raw) Kind() datamodel.Kind { + return datamodel.Kind_Bytes +} +func (Raw) LookupByString(string) (datamodel.Node, error) { + return mixins.Bytes{TypeName: "dagjose.Raw"}.LookupByString("") +} +func (Raw) LookupByNode(datamodel.Node) (datamodel.Node, error) { + return mixins.Bytes{TypeName: "dagjose.Raw"}.LookupByNode(nil) +} +func (Raw) LookupByIndex(idx int64) (datamodel.Node, error) { + return mixins.Bytes{TypeName: "dagjose.Raw"}.LookupByIndex(0) +} +func (Raw) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { + return mixins.Bytes{TypeName: "dagjose.Raw"}.LookupBySegment(seg) +} +func (Raw) MapIterator() datamodel.MapIterator { + return nil +} +func (Raw) ListIterator() datamodel.ListIterator { + return nil +} +func (Raw) Length() int64 { + return -1 +} +func (Raw) IsAbsent() bool { + return false +} +func (Raw) IsNull() bool { + return false +} +func (Raw) AsBool() (bool, error) { + return mixins.Bytes{TypeName: "dagjose.Raw"}.AsBool() +} +func (Raw) AsInt() (int64, error) { + return mixins.Bytes{TypeName: "dagjose.Raw"}.AsInt() +} +func (Raw) AsFloat() (float64, error) { + return mixins.Bytes{TypeName: "dagjose.Raw"}.AsFloat() +} +func (n Raw) AsString() (string, error) { + return encodeBase64Url(n.x), nil +} +func (n Raw) AsBytes() ([]byte, error) { + return n.x, nil +} +func (Raw) AsLink() (datamodel.Link, error) { + return mixins.Bytes{TypeName: "dagjose.Raw"}.AsLink() +} +func (Raw) Prototype() datamodel.NodePrototype { + return _Raw__Prototype{} +} + +type _Raw__Prototype struct{} + +func (_Raw__Prototype) NewBuilder() datamodel.NodeBuilder { + var nb _Raw__Builder + nb.Reset() + return &nb +} + +type _Raw__Builder struct { + _Raw__Assembler +} + +func (nb *_Raw__Builder) Build() datamodel.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Raw__Builder) Reset() { + var w _Raw + var m schema.Maybe + *nb = _Raw__Builder{_Raw__Assembler{w: &w, m: &m}} +} + +type _Raw__Assembler struct { + w *_Raw + m *schema.Maybe +} + +func (na *_Raw__Assembler) reset() {} +func (_Raw__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) { + return mixins.BytesAssembler{TypeName: "dagjose.Raw"}.BeginMap(0) +} +func (_Raw__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) { + return mixins.BytesAssembler{TypeName: "dagjose.Raw"}.BeginList(0) +} +func (na *_Raw__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.BytesAssembler{TypeName: "dagjose.Raw"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + panic("unreachable") +} +func (_Raw__Assembler) AssignBool(bool) error { + return mixins.BytesAssembler{TypeName: "dagjose.Raw"}.AssignBool(false) +} +func (_Raw__Assembler) AssignInt(int64) error { + return mixins.BytesAssembler{TypeName: "dagjose.Raw"}.AssignInt(0) +} +func (_Raw__Assembler) AssignFloat(float64) error { + return mixins.BytesAssembler{TypeName: "dagjose.Raw"}.AssignFloat(0) +} +func (na *_Raw__Assembler) AssignString(v string) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if decodedBytes, err := decodeBase64Url(v); err != nil { + return err + } else { + na.w.x = decodedBytes + *na.m = schema.Maybe_Value + return nil + } +} +func (na *_Raw__Assembler) AssignBytes(v []byte) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + na.w.x = v + *na.m = schema.Maybe_Value + return nil +} +func (_Raw__Assembler) AssignLink(datamodel.Link) error { + return mixins.BytesAssembler{TypeName: "dagjose.Raw"}.AssignLink(nil) +} +func (na *_Raw__Assembler) AssignNode(v datamodel.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Raw); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v2, err := v.AsBytes(); err != nil { + if e, wrongKind := err.(datamodel.ErrWrongKind); wrongKind && (e.ActualKind == datamodel.Kind_String) { + if v2, err := v.AsString(); err != nil { + return err + } else { + return na.AssignString(v2) + } + } + return err + } else { + return na.AssignBytes(v2) + } +} +func (_Raw__Assembler) Prototype() datamodel.NodePrototype { + return _Raw__Prototype{} +} +func (Raw) Type() schema.Type { + return nil +} +func (n Raw) Representation() datamodel.Node { + return (*_Raw__Repr)(n) } -func decodeBase64Url(encoded string) (string, error) { - decoded, err := base64.RawURLEncoding.DecodeString(encoded) - return string(decoded), err +type _Raw__Repr = _Raw + +var _ datamodel.Node = &_Raw__Repr{} + +type _Raw__ReprPrototype = _Raw__Prototype +type _Raw__ReprAssembler = _Raw__Assembler + +func encodeBase64Url(decoded []byte) string { + return base64.RawURLEncoding.EncodeToString(decoded) } + +func decodeBase64Url(encoded string) ([]byte, error) { + decodedBytes, err := base64.RawURLEncoding.DecodeString(encoded) + return decodedBytes, err +} \ No newline at end of file diff --git a/dagjose/multicodec.go b/dagjose/multicodec.go index ec4aa01..19a1cd2 100644 --- a/dagjose/multicodec.go +++ b/dagjose/multicodec.go @@ -25,32 +25,28 @@ func init() { // the codec.Decoder function interface. func Decode(na datamodel.NodeAssembler, r io.Reader) error { // If the passed `NodeAssembler` is not of type `_JOSE__ReprBuilder`, create and use a `_JOSE__ReprBuilder`. - joseBuilder, alreadyJose := na.(*_JOSE__ReprBuilder) + joseBuilder, alreadyJose := na.(*_DecodedJOSE__ReprBuilder) if !alreadyJose { - joseBuilder = Type.JOSE__Repr.NewBuilder().(*_JOSE__ReprBuilder) + joseBuilder = Type.DecodedJOSE__Repr.NewBuilder().(*_DecodedJOSE__ReprBuilder) } // CBOR is a superset of DAG-JOSE and can be used to decode valid DAG-JOSE objects: // https://specs.ipld.io/block-layer/codecs/dag-jose.html - err := cbor.Decode(joseBuilder, r) - if err != nil { + if err := cbor.Decode(joseBuilder, r); err != nil { return err } // If `payload` is present but `link` is not, add `link` with the corresponding encoded CID. payloadNode := &joseBuilder.w.payload linkNode := &joseBuilder.w.link if payloadNode.Exists() && !linkNode.Exists() { - link, err := Type.Base64Url.Link(&payloadNode.v) - if err != nil { + if link, err := Type.Base64Url.Link(&payloadNode.v); err != nil { return err + } else { + linkNode.m = schema.Maybe_Value + linkNode.v = *link } - linkNode.m = schema.Maybe_Value - linkNode.v = *link } // The "representation" node gives an accurate view of fields that are actually present joseNode := joseBuilder.Build().(schema.TypedNode).Representation() - if err != nil { - return err - } // If the passed `NodeAssembler` is not of type `_JOSE__ReprBuilder`, copy the constructed `_JOSE__Repr` into the // caller's `NodeAssembler`. if !alreadyJose { @@ -64,8 +60,7 @@ func Decode(na datamodel.NodeAssembler, r io.Reader) error { func Encode(n datamodel.Node, w io.Writer) error { rebuildRequired := false // If `link` and `payload` are present, make sure they match. - linkNode, err := n.LookupByString("link") - if err != nil { + if linkNode, err := n.LookupByString("link"); err != nil { // It's ok for `link` to be absent (even if `payload` was present), but if some other error occurred, // return it. if _, linkNotFound := err.(datamodel.ErrNotExists); !linkNotFound { @@ -97,8 +92,8 @@ func Encode(n datamodel.Node, w io.Writer) error { rebuildRequired = true } // If the passed `Node` is not of type `_JOSE__Repr`, convert it to `_JOSE__Repr`. - if _, alreadyJose := n.(*_JOSE__Repr); !alreadyJose || rebuildRequired { - joseBuilder := Type.JOSE__Repr.NewBuilder().(*_JOSE__ReprBuilder) + if _, alreadyJose := n.(*_EncodedJOSE__Repr); !alreadyJose || rebuildRequired { + joseBuilder := Type.EncodedJOSE__Repr.NewBuilder().(*_EncodedJOSE__ReprBuilder) // Copy the passed `Node` into `_JOSE__ReprBuilder`, which applies all the necessary validations required to // construct a `_JOSE__Repr` node. if err := datamodel.Copy(n, joseBuilder); err != nil { @@ -106,6 +101,7 @@ func Encode(n datamodel.Node, w io.Writer) error { } // Mark `link` as absent because we do not want to encode it joseBuilder.w.link.m = schema.Maybe_Absent + joseBuilder.w.link.v.x = nil // The "representation" node gives an accurate view of fields that are actually present n = joseBuilder.Build().(schema.TypedNode).Representation() }