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 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 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 // 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{ 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
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 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 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.