mirror of
https://github.com/safing/structures
synced 2025-09-01 18:29:02 +00:00
Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
|
7b9b0494da | ||
|
bc6ff03b3d | ||
|
569c3ec6e0 |
4 changed files with 8 additions and 7 deletions
|
@ -93,7 +93,7 @@ func Dump(t interface{}, format uint8) ([]byte, error) {
|
||||||
|
|
||||||
// DumpIndent stores the interface as a dsd formatted data structure with indentation, if available.
|
// DumpIndent stores the interface as a dsd formatted data structure with indentation, if available.
|
||||||
func DumpIndent(t interface{}, format uint8, indent string) ([]byte, error) {
|
func DumpIndent(t interface{}, format uint8, indent string) ([]byte, error) {
|
||||||
data, err := dumpWithoutIdentifier(t, format, indent)
|
data, err := DumpWithoutIdentifier(t, format, indent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,8 @@ func DumpIndent(t interface{}, format uint8, indent string) ([]byte, error) {
|
||||||
return append(varint.Pack8(format), data...), nil
|
return append(varint.Pack8(format), data...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpWithoutIdentifier(t interface{}, format uint8, indent string) ([]byte, error) {
|
// DumpWithoutIdentifier stores the interface as a data structure, without format identifier, but with indentation, if specified and available.
|
||||||
|
func DumpWithoutIdentifier(t interface{}, format uint8, indent string) ([]byte, error) {
|
||||||
format, ok := ValidateSerializationFormat(format)
|
format, ok := ValidateSerializationFormat(format)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ErrIncompatibleFormat
|
return nil, ErrIncompatibleFormat
|
||||||
|
|
|
@ -65,7 +65,7 @@ func DumpToHTTPRequest(r *http.Request, t interface{}, format uint8) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize data.
|
// Serialize data.
|
||||||
data, err := dumpWithoutIdentifier(t, format, "")
|
data, err := DumpWithoutIdentifier(t, format, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("dsd: failed to serialize: %w", err)
|
return fmt.Errorf("dsd: failed to serialize: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ func MimeDump(t any, accept string) (data []byte, mimeType string, format uint8,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize and return.
|
// Serialize and return.
|
||||||
data, err = dumpWithoutIdentifier(t, format, "")
|
data, err = DumpWithoutIdentifier(t, format, "")
|
||||||
return data, mimeType, format, err
|
return data, mimeType, format, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -7,7 +7,7 @@ toolchain go1.21.2
|
||||||
require (
|
require (
|
||||||
github.com/fxamacker/cbor/v2 v2.7.0
|
github.com/fxamacker/cbor/v2 v2.7.0
|
||||||
github.com/ghodss/yaml v1.0.0
|
github.com/ghodss/yaml v1.0.0
|
||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.9.0
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1
|
github.com/vmihailenco/msgpack/v5 v5.4.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -11,8 +11,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
|
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
||||||
|
|
Loading…
Add table
Reference in a new issue