Skip to content

Plugs/Socket

Names that start with a single $ are type sockets, starting out as an empty type, and intended to be extended via /=. Names that start with a double $$ are group sockets, starting out as an empty group choice, and intended to be extended via //=. In either case, it is not an error if there is no definition for a socket at all; this then means there is no way to satisfy the rule (i.e., the choice is empty). 1

Below is an example of a group socket - $$Location

plug_socket.cddl
1
2
3
4
5
6
Person = (
    name: tstr,
    age: uint,

    Location: $$Location
)

cddlc interpretes undefined plugs/sockets as Golang types that are defined in the same package as the generated file. In this case plugs/sockets are not differentiated and the generated output expects the plug/socket to be defined in the same package.

Generating code from this using

cddlc generate --source plug_socket.cddl --out lib/plug_socket.go --package foo

exports the Go declarations in "lib/plug_socket.go". To satisfy the Location type in Go a file with this declaration must be added.

/*
  File generated using `cddlc.exe gen`. DO NOT EDIT
*/

package foo

// (cddlc) Ident: Person
type Person struct {
    Name     string
    Age      uint
    Location Location
}

// Valid evaluates type constraints on Person and returns nil if valid 
// else it returns a list of validation errors
func (person *Person) Valid() error {
    return nil
}
package foo

import "time"

type Planet int

const (
    Mercury Planet = iota
    Venus
    Earth
    Mars
)

type Location struct {
    Planet  Planet
    Country string

    FirstOpened time.Time
}

  1. https://www.rfc-editor.org/rfc/inline-errata/rfc8610.html