Documentation
¶
Index ¶
- Constants
- Variables
- type CBORMarshaler
- type CBORReader
- func (r *CBORReader) Read() (interface{}, error)
- func (r *CBORReader) ReadArray() ([]TaggedElement, error)
- func (r *CBORReader) ReadBytes() ([]byte, error)
- func (r *CBORReader) ReadFloat() (float64, error)
- func (r *CBORReader) ReadInt() (int, error)
- func (r *CBORReader) ReadIntArray() ([]int, error)
- func (r *CBORReader) ReadIntMap() (map[int]TaggedElement, error)
- func (r *CBORReader) ReadIntMapUntagged() (map[int]interface{}, error)
- func (r *CBORReader) ReadString() (string, error)
- func (r *CBORReader) ReadStringArray() ([]string, error)
- func (r *CBORReader) ReadStringMap() (map[string]TaggedElement, error)
- func (r *CBORReader) ReadTag() (CBORTag, error)
- func (r *CBORReader) ReadTime() (time.Time, error)
- func (r *CBORReader) ReadUint() (uint64, error)
- func (r *CBORReader) RegisterCBORTag(tag CBORTag, inst interface{}) error
- func (r *CBORReader) Unmarshal(x interface{}) error
- func (r *CBORReader) UntagArray(in []TaggedElement) []interface{}
- func (r *CBORReader) UntagIntMap(in map[int]TaggedElement) map[int]interface{}
- func (r *CBORReader) UntagStringMap(in map[string]TaggedElement) map[string]interface{}
- type CBORTag
- type CBORUnmarshaler
- type CBORWriter
- func (w *CBORWriter) Marshal(x interface{}) error
- func (w *CBORWriter) RegisterCBORTag(tag CBORTag, inst interface{}) error
- func (w *CBORWriter) WriteArray(a []interface{}) error
- func (w *CBORWriter) WriteBool(b bool) error
- func (w *CBORWriter) WriteBytes(b []byte) error
- func (w *CBORWriter) WriteFloat(f float64) error
- func (w *CBORWriter) WriteInt(i int) error
- func (w *CBORWriter) WriteIntArray(a []int) error
- func (w *CBORWriter) WriteIntMap(m map[int]interface{}) error
- func (w *CBORWriter) WriteNil() error
- func (w *CBORWriter) WriteString(s string) error
- func (w *CBORWriter) WriteStringArray(a []string) error
- func (w *CBORWriter) WriteStringMap(m map[string]interface{}) error
- func (w *CBORWriter) WriteTag(t CBORTag) error
- func (w *CBORWriter) WriteTime(t time.Time) error
- type DateTimePref
- type DebugWriter
- type TaggedElement
Constants ¶
const ( TagDateTimeString = 0 TagDateTimeEpoch = 1 TagURI = 32 TagBase64URL = 33 TagBase64 = 34 TagUUID = 37 )
const ( // DateTimePrefInt causes a timestamp to be encoded as an int. DateTimePrefInt = iota // DateTimePrefFloat causes a timestamp to be encoded as a float. DateTimePrefFloat // DateTimePrefString causes a timestamp to be encoded as a String. DateTimePrefString )
Variables ¶
var ( CBORTypeReadError = errors.New("invalid CBOR type for typed read") InvalidCBORError = errors.New("invalid CBOR") // UnsupportedTypeReadError is an explicit error for types we do not support. // This is different to encountering something which is not in the RFC. UnsupportedTypeReadError = errors.New("unsupported type encountered in read") )
Functions ¶
This section is empty.
Types ¶
type CBORMarshaler ¶
type CBORMarshaler interface {
MarshalCBOR(w *CBORWriter) error
}
CBORMarshaler represents an object that can write itself to a CBORWriter
type CBORReader ¶
type CBORReader struct {
// contains filtered or unexported fields
}
CBORReader provides functionality to decode encoded CBOR to structures or to manually read elements out of a byte slice.
func NewCBORReader ¶
func NewCBORReader(in io.Reader) *CBORReader
NewCBORReader creates a new instance of the CBORReader.
func (*CBORReader) Read ¶
func (r *CBORReader) Read() (interface{}, error)
func (*CBORReader) ReadArray ¶
func (r *CBORReader) ReadArray() ([]TaggedElement, error)
ReadArray reads an arbitrary array type.
func (*CBORReader) ReadBytes ¶
func (r *CBORReader) ReadBytes() ([]byte, error)
ReadBytes reads the byte array type.
func (*CBORReader) ReadFloat ¶
func (r *CBORReader) ReadFloat() (float64, error)
ReadFloat reads a floating point type.
func (*CBORReader) ReadInt ¶
func (r *CBORReader) ReadInt() (int, error)
ReadInt reads a numerical type and sets the sign accordingly.
func (*CBORReader) ReadIntArray ¶
func (r *CBORReader) ReadIntArray() ([]int, error)
ReadIntArray reads an array of integers.
func (*CBORReader) ReadIntMap ¶
func (r *CBORReader) ReadIntMap() (map[int]TaggedElement, error)
ReadIntMap reads an integer keyed map.
func (*CBORReader) ReadIntMapUntagged ¶
func (r *CBORReader) ReadIntMapUntagged() (map[int]interface{}, error)
func (*CBORReader) ReadString ¶
func (r *CBORReader) ReadString() (string, error)
ReadString reads a string type.
func (*CBORReader) ReadStringArray ¶
func (r *CBORReader) ReadStringArray() ([]string, error)
ReadStringArray reads an array of strings.
func (*CBORReader) ReadStringMap ¶
func (r *CBORReader) ReadStringMap() (map[string]TaggedElement, error)
ReadStringMap reads a CBOR map type.
func (*CBORReader) ReadTag ¶
func (r *CBORReader) ReadTag() (CBORTag, error)
ReadTag reads a CBOR tag type.
func (*CBORReader) ReadTime ¶
func (r *CBORReader) ReadTime() (time.Time, error)
ReadTime reads a timestamp.
func (*CBORReader) ReadUint ¶
func (r *CBORReader) ReadUint() (uint64, error)
ReadUint reads an numerical type but discards the sign information if any.
func (*CBORReader) RegisterCBORTag ¶
func (r *CBORReader) RegisterCBORTag(tag CBORTag, inst interface{}) error
RegisterCBORTag configures a mapping from a CBOR tag to a specific struct.
func (*CBORReader) Unmarshal ¶
func (r *CBORReader) Unmarshal(x interface{}) error
Unmarshal attempts to read the next value from the CBOR reader and store it in the value pointed to by v, according to v's type. Returns CBORTypeReadError if the type does not match or cannot be made to match. Values are handled as in Marshal().
func (*CBORReader) UntagArray ¶
func (r *CBORReader) UntagArray(in []TaggedElement) []interface{}
UntagArray takes an array containing optionally tagged elements and removes those tags recursively. Also supports nested maps.
func (*CBORReader) UntagIntMap ¶
func (r *CBORReader) UntagIntMap(in map[int]TaggedElement) map[int]interface{}
func (*CBORReader) UntagStringMap ¶
func (r *CBORReader) UntagStringMap(in map[string]TaggedElement) map[string]interface{}
UntagStringMap takes a map which contains optionally tagged elements and removes the tags from the map and any nested maps recursively. Also supports nested arrays.
type CBORUnmarshaler ¶
type CBORUnmarshaler interface {
UnmarshalCBOR(r *CBORReader) error
}
type CBORWriter ¶
type CBORWriter struct {
// contains filtered or unexported fields
}
CBORWriter writes CBOR to an output stream. It provides a relatively low-level interface, allowing the caller to write typed data to the stream as CBOR, as well as a higher-level Marshal interface which uses reflection to properly encode arbitrary objects as CBOR.
func NewCBORWriter ¶
func NewCBORWriter(out io.Writer) *CBORWriter
NewCBORWriter creates a new CBORWriter around a given output stream (io.Writer).
func (*CBORWriter) Marshal ¶
func (w *CBORWriter) Marshal(x interface{}) error
Marshal marshals an arbitrary object to the output stream using reflection. If the object is a primitive type, it will be marshaled as such. If it implements CBORMarshaler, its MarshalCBOR function will be called. If the object is a structure with CBOR struct tags, those struct tags will be used. If the object is a struct without CBOR struct tags, the struct will be marshaled as a map of strings to objects using the names of the public members of the struct.
func (*CBORWriter) RegisterCBORTag ¶
func (w *CBORWriter) RegisterCBORTag(tag CBORTag, inst interface{}) error
RegisterCBORTag adds a CBOR tag for annotating a serialized struct.
func (*CBORWriter) WriteArray ¶
func (w *CBORWriter) WriteArray(a []interface{}) error
WriteArray writes an arbitrary slice to the output stream. Each of the elements of the array will be reflected and written as appropriate.
func (*CBORWriter) WriteBool ¶
func (w *CBORWriter) WriteBool(b bool) error
WriteBool writes a boolean value to the output stream.
func (*CBORWriter) WriteBytes ¶
func (w *CBORWriter) WriteBytes(b []byte) error
WriteBytes writes a byte array to the output stream.
func (*CBORWriter) WriteFloat ¶
func (w *CBORWriter) WriteFloat(f float64) error
WriteFloat writes a floating point number to the output stream.
func (*CBORWriter) WriteInt ¶
func (w *CBORWriter) WriteInt(i int) error
WriteInt writes an integer to the output stream.
func (*CBORWriter) WriteIntArray ¶
func (w *CBORWriter) WriteIntArray(a []int) error
WriteIntArray writes a slice of integers to the output stream.
func (*CBORWriter) WriteIntMap ¶
func (w *CBORWriter) WriteIntMap(m map[int]interface{}) error
WriteIntMap writes a map keyed by integers to arbitrary types to the output stream. Each of the values of the map will be reflected and written as appropriate.
func (*CBORWriter) WriteNil ¶
func (w *CBORWriter) WriteNil() error
WriteNil writes a nil to the output stream
func (*CBORWriter) WriteString ¶
func (w *CBORWriter) WriteString(s string) error
WriteString writes a string to the output stream.
func (*CBORWriter) WriteStringArray ¶
func (w *CBORWriter) WriteStringArray(a []string) error
WriteStringArray writes a slice of strings to the output stream.
func (*CBORWriter) WriteStringMap ¶
func (w *CBORWriter) WriteStringMap(m map[string]interface{}) error
WriteStringMap writes a map keyed by strings to arbitrary types to the output stream. Each of the values of the map will be reflected and written as appropriate.
func (*CBORWriter) WriteTag ¶
func (w *CBORWriter) WriteTag(t CBORTag) error
WriteTag writes a CBOR tag to the output stream. CBOR tags are used to note the semantics of the following object.
type DateTimePref ¶
type DateTimePref int
DateTimePref indicates the format for marshaling timestamps.
type DebugWriter ¶
type DebugWriter struct {
// contains filtered or unexported fields
}
DebugWriter wraps a writer and provides functionality to dump what was written to the writer.
func NewDebugWriter ¶
func NewDebugWriter(underlying io.Writer) *DebugWriter
NewDebugWriter creates a DebugWriter instance.
func (*DebugWriter) RetrieveReset ¶
func (dw *DebugWriter) RetrieveReset() []byte
RetrieveReset returns the current buffer and resets it for future writing. Note that the buffer is unchanged, writing to the buffer will overwrite the buffer's underlying bytes.
type TaggedElement ¶
type TaggedElement struct { Tag CBORTag Value interface{} }
TaggedElement is used to wrap elements which may be tagged for writing.