mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Add yaml support to DSD
This commit is contained in:
parent
4451b6985c
commit
277a0ea669
2 changed files with 15 additions and 0 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/fxamacker/cbor/v2"
|
"github.com/fxamacker/cbor/v2"
|
||||||
|
"github.com/ghodss/yaml"
|
||||||
"github.com/vmihailenco/msgpack/v5"
|
"github.com/vmihailenco/msgpack/v5"
|
||||||
|
|
||||||
"github.com/safing/portbase/formats/varint"
|
"github.com/safing/portbase/formats/varint"
|
||||||
|
@ -41,6 +42,12 @@ func LoadAsFormat(data []byte, format uint8, t interface{}) (err error) {
|
||||||
return fmt.Errorf("dsd: failed to unpack json: %w, data: %s", err, utils.SafeFirst16Bytes(data))
|
return fmt.Errorf("dsd: failed to unpack json: %w, data: %s", err, utils.SafeFirst16Bytes(data))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
case YAML:
|
||||||
|
err = yaml.Unmarshal(data, t)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("dsd: failed to unpack yaml: %w, data: %s", err, utils.SafeFirst16Bytes(data))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
case CBOR:
|
case CBOR:
|
||||||
err = cbor.Unmarshal(data, t)
|
err = cbor.Unmarshal(data, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -121,6 +128,11 @@ func dumpWithoutIdentifier(t interface{}, format uint8, indent string) ([]byte,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
case YAML:
|
||||||
|
data, err = yaml.Marshal(t)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
case CBOR:
|
case CBOR:
|
||||||
data, err = cbor.Marshal(t)
|
data, err = cbor.Marshal(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -19,6 +19,7 @@ const (
|
||||||
GenCode = 71 // G
|
GenCode = 71 // G
|
||||||
JSON = 74 // J
|
JSON = 74 // J
|
||||||
MsgPack = 77 // M
|
MsgPack = 77 // M
|
||||||
|
YAML = 89 // Y
|
||||||
|
|
||||||
// Compression types.
|
// Compression types.
|
||||||
GZIP = 90 // Z
|
GZIP = 90 // Z
|
||||||
|
@ -48,6 +49,8 @@ func ValidateSerializationFormat(format uint8) (validatedFormat uint8, ok bool)
|
||||||
return format, true
|
return format, true
|
||||||
case JSON:
|
case JSON:
|
||||||
return format, true
|
return format, true
|
||||||
|
case YAML:
|
||||||
|
return format, true
|
||||||
case MsgPack:
|
case MsgPack:
|
||||||
return format, true
|
return format, true
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Reference in a new issue