nimona/go-nimona

View on GitHub
peer_docgen.go

Summary

Maintainability
A
0 mins
Test Coverage
// Code generated by nimona.io. DO NOT EDIT.

package nimona

import (
    "github.com/vikyd/zero"

    "nimona.io/tilde"
)

var _ = zero.IsZeroVal
var _ = tilde.NewScanner

func (t *PeerInfo) Document() *Document {
    return NewDocument(t.Map())
}

func (t *PeerInfo) Map() tilde.Map {
    m := tilde.Map{}

    // # t.$type
    //
    // Type: string, Kind: string, TildeKind: InvalidValueKind0
    // IsSlice: false, IsStruct: false, IsPointer: false
    {
        m.Set("$type", tilde.String("core/peer/info"))
    }

    // # t.Addresses
    //
    // Type: []nimona.PeerAddr, Kind: slice, TildeKind: List
    // IsSlice: true, IsStruct: false, IsPointer: false
    //
    // ElemType: nimona.PeerAddr, ElemKind: struct
    // IsElemSlice: false, IsElemStruct: true, IsElemPointer: false
    {
        if !zero.IsZeroVal(t.Addresses) {
            sm := tilde.List{}
            for i, _ := range t.Addresses {
                v := t.Addresses[i]
                if !zero.IsZeroVal(v) {
                    sm = append(sm, v.Map())
                }
            }
            m.Set("addresses", sm)
        }
    }

    // # t.Metadata
    //
    // Type: nimona.Metadata, Kind: struct, TildeKind: Map
    // IsSlice: false, IsStruct: true, IsPointer: false
    {
        if !zero.IsZeroVal(t.Metadata) {
            m.Set("$metadata", t.Metadata.Map())
        }
    }

    // # t.PublicKey
    //
    // Type: nimona.PublicKey, Kind: slice, TildeKind: Bytes
    // IsSlice: true, IsStruct: false, IsPointer: false
    //
    // ElemType: uint8, ElemKind: uint8
    // IsElemSlice: false, IsElemStruct: false, IsElemPointer: false
    {
        if !zero.IsZeroVal(t.PublicKey) {
            m.Set("publicKey", tilde.Bytes(t.PublicKey))
        }
    }

    return m
}

func (t *PeerInfo) FromDocument(d *Document) error {
    return t.FromMap(d.Map())
}

func (t *PeerInfo) FromMap(d tilde.Map) error {
    *t = PeerInfo{}

    // # t.Addresses
    //
    // Type: []nimona.PeerAddr, Kind: slice, TildeKind: List
    // IsSlice: true, IsStruct: false, IsPointer: false
    //
    // ElemType: nimona.PeerAddr, ElemKind: struct, ElemTildeKind: Map
    // IsElemSlice: false, IsElemStruct: true, IsElemPointer: false
    {
        sm := []PeerAddr{}
        if vs, err := d.Get("addresses"); err == nil {
            if vs, ok := vs.(tilde.List); ok {
                for _, vi := range vs {
                    if v, ok := vi.(tilde.Map); ok {
                        e := PeerAddr{}
                        d := NewDocument(v)
                        e.FromDocument(d)
                        sm = append(sm, e)
                    }
                }
            }
        }
        if len(sm) > 0 {
            t.Addresses = sm
        }
    }

    // # t.Metadata
    //
    // Type: nimona.Metadata, Kind: struct, TildeKind: Map
    // IsSlice: false, IsStruct: true, IsPointer: false
    {
        if v, err := d.Get("$metadata"); err == nil {
            if v, ok := v.(tilde.Map); ok {
                e := Metadata{}
                d := NewDocument(v)
                e.FromDocument(d)
                t.Metadata = e
            }
        }
    }

    // # t.PublicKey
    //
    // Type: nimona.PublicKey, Kind: slice, TildeKind: Bytes
    // IsSlice: true, IsStruct: false, IsPointer: false
    //
    // ElemType: uint8, ElemKind: uint8, ElemTildeKind: InvalidValueKind0
    // IsElemSlice: false, IsElemStruct: false, IsElemPointer: false
    {
        if v, err := d.Get("publicKey"); err == nil {
            if v, ok := v.(tilde.Bytes); ok {
                t.PublicKey = PublicKey(v)
            }
        }
    }

    return nil
}
func (t *PeerKey) Document() *Document {
    return NewDocument(t.Map())
}

func (t *PeerKey) Map() tilde.Map {
    m := tilde.Map{}

    // # t.$type
    //
    // Type: string, Kind: string, TildeKind: InvalidValueKind0
    // IsSlice: false, IsStruct: false, IsPointer: false
    {
        m.Set("$type", tilde.String("core/peer/key"))
    }

    // # t.PublicKey
    //
    // Type: nimona.PublicKey, Kind: slice, TildeKind: Bytes
    // IsSlice: true, IsStruct: false, IsPointer: false
    //
    // ElemType: uint8, ElemKind: uint8
    // IsElemSlice: false, IsElemStruct: false, IsElemPointer: false
    {
        if !zero.IsZeroVal(t.PublicKey) {
            m.Set("publicKey", tilde.Bytes(t.PublicKey))
        }
    }

    return m
}

func (t *PeerKey) FromDocument(d *Document) error {
    return t.FromMap(d.Map())
}

func (t *PeerKey) FromMap(d tilde.Map) error {
    *t = PeerKey{}

    // # t.PublicKey
    //
    // Type: nimona.PublicKey, Kind: slice, TildeKind: Bytes
    // IsSlice: true, IsStruct: false, IsPointer: false
    //
    // ElemType: uint8, ElemKind: uint8, ElemTildeKind: InvalidValueKind0
    // IsElemSlice: false, IsElemStruct: false, IsElemPointer: false
    {
        if v, err := d.Get("publicKey"); err == nil {
            if v, ok := v.(tilde.Bytes); ok {
                t.PublicKey = PublicKey(v)
            }
        }
    }

    return nil
}