Fixed Values
The four supported fixed value types are nil
/null
, true
, false
From the definition file fixed.cddl
containing the following content,
fixed.cddl |
---|
| null-type = null
true-alt = true
false-val = false
|
go code can be generated by invoking
cddlc generate --source fixed.cddl --out lib/fixed.go --package foo
This generates the declarations and validation methods. Since the types are directly enforced by the Go type checker, the Valid() methods return nil by default. All values are public by default with identifiers formatted as PascalCase.
fixed.go |
---|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 | /*
File generated using `cddlc.exe gen`. DO NOT EDIT
*/
package foo
// (cddlc) Ident: null-type
type NullType nil
// Valid evaluates type constraints on null-type and returns nil if valid
// else it returns a list of validation errors
func (null-type *NullType) Valid() error {
return nil
}
// (cddlc) Ident: true-alt
var TrueAlt = true
// Valid evaluates type constraints on true-alt and returns nil if valid
// else it returns a list of validation errors
func (true-alt *TrueAlt) Valid() error {
return nil
}
// (cddlc) Ident: false-val
var FalseVal = false
// Valid evaluates type constraints on false-val and returns nil if valid
// else it returns a list of validation errors
func (false-val *FalseVal) Valid() error {
return nil
}
|