dsd

package
v0.16.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2022 License: GPL-3.0 Imports: 12 Imported by: 12

Documentation

Index

Constants

View Source
const (
	AUTO = 0

	// Serialization types.
	RAW     = 1
	CBOR    = 67 // C
	GenCode = 71 // G
	JSON    = 74 // J
	MsgPack = 77 // M

	// Compression types.
	GZIP = 90 // Z

	// Special types.
	LIST = 76 // L
)

Format types.

Variables

View Source
var (
	ErrIncompatibleFormat = errors.New("dsd: format is incompatible with operation")
	ErrIsRaw              = errors.New("dsd: given data is in raw format")
	ErrUnknownFormat      = errors.New("dsd: format is unknown")
)

Errors.

View Source
var (
	DefaultSerializationFormat uint8 = JSON
	DefaultCompressionFormat   uint8 = GZIP
)

Default Formats.

View Source
var (
	ErrMissingBody        = errors.New("dsd: missing http body")
	ErrMissingContentType = errors.New("dsd: missing http content type")
)

HTTP Related Errors.

View Source
var (
	FormatToMimeType = map[uint8]string{
		JSON:    "application/json; charset=utf-8",
		CBOR:    "application/cbor",
		MsgPack: "application/msgpack",
	}
	MimeTypeToFormat = map[string]uint8{
		"application/json":    JSON,
		"application/cbor":    CBOR,
		"application/msgpack": MsgPack,
	}
)

Format and MimeType mappings.

Functions

func DecompressAndLoad added in v0.4.1

func DecompressAndLoad(data []byte, compression uint8, t interface{}) (format uint8, err error)

DecompressAndLoad decompresses the data using the specified compression format and then loads the resulting data blob into the interface.

func Dump

func Dump(t interface{}, format uint8) ([]byte, error)

Dump stores the interface as a dsd formatted data structure.

func DumpAndCompress added in v0.4.1

func DumpAndCompress(t interface{}, format uint8, compression uint8) ([]byte, error)

DumpAndCompress stores the interface as a dsd formatted data structure and compresses the resulting data.

func DumpIndent added in v0.4.1

func DumpIndent(t interface{}, format uint8, indent string) ([]byte, error)

DumpIndent stores the interface as a dsd formatted data structure with indentation, if available.

func DumpToHTTPRequest added in v0.13.0

func DumpToHTTPRequest(r *http.Request, t interface{}, format uint8) error

DumpToHTTPRequest dumps the given data to the HTTP request using the given format. It also sets the Accept header to the same format.

func DumpToHTTPResponse added in v0.13.0

func DumpToHTTPResponse(w http.ResponseWriter, r *http.Request, t interface{}) error

DumpToHTTPResponse dumpts the given data to the HTTP response, using the format defined in the request's Accept header.

func Load

func Load(data []byte, t interface{}) (format uint8, err error)

Load loads an dsd structured data blob into the given interface.

func LoadAsFormat

func LoadAsFormat(data []byte, format uint8, t interface{}) (err error)

LoadAsFormat loads a data blob into the interface using the specified format.

func LoadFromHTTPRequest added in v0.13.0

func LoadFromHTTPRequest(r *http.Request, t interface{}) (format uint8, err error)

LoadFromHTTPRequest loads the data from the body into the given interface.

func LoadFromHTTPResponse added in v0.13.0

func LoadFromHTTPResponse(resp *http.Response, t interface{}) (format uint8, err error)

LoadFromHTTPResponse loads the data from the body into the given interface. Closing the body is left to the caller.

func RequestHTTPResponseFormat added in v0.13.0

func RequestHTTPResponseFormat(r *http.Request, format uint8) (mimeType string, err error)

RequestHTTPResponseFormat sets the Accept header to the given format.

func ValidateCompressionFormat added in v0.13.0

func ValidateCompressionFormat(format uint8) (validatedFormat uint8, ok bool)

ValidateCompressionFormat validates if the format is for compression, and returns the validated format as well as the result of the validation. If called on the AUTO format, it returns the default compression format.

func ValidateSerializationFormat added in v0.13.0

func ValidateSerializationFormat(format uint8) (validatedFormat uint8, ok bool)

ValidateSerializationFormat validates if the format is for serialization, and returns the validated format as well as the result of the validation. If called on the AUTO format, it returns the default serialization format.

Types

type GenCodeCompatible added in v0.3.0

type GenCodeCompatible interface {
	// GenCodeMarshal gencode marshalls the struct into the given byte array, or a new one if its too small.
	GenCodeMarshal(buf []byte) ([]byte, error)
	// GenCodeUnmarshal gencode unmarshalls the struct and returns the bytes read.
	GenCodeUnmarshal(buf []byte) (uint64, error)
}

GenCodeCompatible is an interface to identify and use gencode compatible structs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL