ppforge/protocol/field.go

54 lines
995 B
Go
Raw Normal View History

package protocol
import "encoding/json"
type Field struct {
Name string // Name of the Field
Desc string // Lengthy description
Regex string // Regex to recognize values
Size int // Size in bits!
SubFields []Field // Possible sub-fields
Optional bool // Is this field required?
Payload bool // Is this field the payload or next protocol level?
JavaScript string
}
2023-04-11 16:05:24 +02:00
type ProtocolFieldReferencer interface {
GetProtocolField() *Field
SetProtocolField(f *Field)
}
func (f *Field) ToJson() string {
b, err := json.Marshal(*f)
if err != nil {
return ""
}
return string(b)
}
func NewEmptyField() *Field {
f := Field{}
return &f
}
func NewField(
name string,
desc string,
regex string,
size int,
subfields []Field,
optional bool,
payload bool,
) *Field {
f := Field{
Name: name,
Desc: desc,
Regex: regex,
Size: size,
SubFields: subfields,
Optional: optional,
Payload: payload,
}
return &f
}