Expose dsd.Dump without Identifier ()

This commit is contained in:
Daniel Hååvi 2025-02-21 10:53:32 +01:00 committed by GitHub
parent bc6ff03b3d
commit 7b9b0494da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View file

@ -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

View file

@ -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
} }