Documentation ¶
Index ¶
- Constants
- Variables
- func DecompressAndLoad(data []byte, compression uint8, t interface{}) (format uint8, err error)
- func Dump(t interface{}, format uint8) ([]byte, error)
- func DumpAndCompress(t interface{}, format uint8, compression uint8) ([]byte, error)
- func DumpIndent(t interface{}, format uint8, indent string) ([]byte, error)
- func DumpToHTTPRequest(r *http.Request, t interface{}, format uint8) error
- func DumpToHTTPResponse(w http.ResponseWriter, r *http.Request, t interface{}) error
- func FormatFromAccept(accept string) (format uint8)
- func Load(data []byte, t interface{}) (format uint8, err error)
- func LoadAsFormat(data []byte, format uint8, t interface{}) (err error)
- func LoadFromHTTPRequest(r *http.Request, t interface{}) (format uint8, err error)
- func LoadFromHTTPResponse(resp *http.Response, t interface{}) (format uint8, err error)
- func MimeDump(t any, accept string) (data []byte, mimeType string, format uint8, err error)
- func MimeLoad(data []byte, accept string, t interface{}) (format uint8, err error)
- func RequestHTTPResponseFormat(r *http.Request, format uint8) (mimeType string, err error)
- func ValidateCompressionFormat(format uint8) (validatedFormat uint8, ok bool)
- func ValidateSerializationFormat(format uint8) (validatedFormat uint8, ok bool)
- type GenCodeCompatible
Constants ¶
const ( AUTO = 0 // Serialization types. RAW = 1 CBOR = 67 // C GenCode = 71 // G JSON = 74 // J MsgPack = 77 // M YAML = 89 // Y // Compression types. GZIP = 90 // Z // Special types. LIST = 76 // L )
Format types.
Variables ¶
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.
var ( DefaultSerializationFormat uint8 = JSON DefaultCompressionFormat uint8 = GZIP )
Default Formats.
var ( ErrMissingBody = errors.New("dsd: missing http body") ErrMissingContentType = errors.New("dsd: missing http content type") )
HTTP Related Errors.
var ( FormatToMimeType = map[uint8]string{ CBOR: "application/cbor", JSON: "application/json", MsgPack: "application/msgpack", YAML: "application/yaml", } MimeTypeToFormat = map[string]uint8{ "cbor": CBOR, "json": JSON, "msgpack": MsgPack, "yaml": YAML, "yml": YAML, } )
Format and MimeType mappings.
Functions ¶
func DecompressAndLoad ¶ added in v0.4.1
DecompressAndLoad decompresses the data using the specified compression format and then loads the resulting data blob into the interface.
func DumpAndCompress ¶ added in v0.4.1
DumpAndCompress stores the interface as a dsd formatted data structure and compresses the resulting data.
func DumpIndent ¶ added in v0.4.1
DumpIndent stores the interface as a dsd formatted data structure with indentation, if available.
func DumpToHTTPRequest ¶ added in v0.13.0
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 FormatFromAccept ¶ added in v0.18.3
FormatFromAccept returns the format for the given accept definition. The accept parameter matches the format of the HTTP Accept header. Special cases, in this order: - If accept is an empty string: returns default serialization format. - If accept contains no supported format, but a wildcard: returns default serialization format. - If accept contains no supported format, and no wildcard: returns AUTO format.
func LoadAsFormat ¶
LoadAsFormat loads a data blob into the interface using the specified format.
func LoadFromHTTPRequest ¶ added in v0.13.0
LoadFromHTTPRequest loads the data from the body into the given interface.
func LoadFromHTTPResponse ¶ added in v0.13.0
LoadFromHTTPResponse loads the data from the body into the given interface. Closing the body is left to the caller.
func MimeDump ¶ added in v0.18.2
MimeDump dumps the given interface based on the given mime type accept header.
func MimeLoad ¶ added in v0.18.2
MimeLoad loads the given data into the interface based on the given mime type accept header.
func RequestHTTPResponseFormat ¶ added in v0.13.0
RequestHTTPResponseFormat sets the Accept header to the given format.
func ValidateCompressionFormat ¶ added in v0.13.0
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
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.