Documentation
¶
Index ¶
- func DecodeMapValue(v any, mv *types.MapValue) error
- func Marshal(v any) ([]byte, error)
- func MarshalToWriter(v any, w *Writer) error
- func UnmarshalFromReader(v any, r *Reader) error
- type InvalidUTF8Errordeprecated
- type Reader
- func (r *Reader) GetBuffer() *bytes.Buffer
- func (r *Reader) Read(p []byte) (n int, err error)
- func (r *Reader) ReadArray() ([]types.FieldValue, error)
- func (r *Reader) ReadBoolean() (bool, error)
- func (r *Reader) ReadByte() (byte, error)
- func (r *Reader) ReadByteArray() ([]byte, error)
- func (r *Reader) ReadByteArrayWithInt() ([]byte, error)
- func (r *Reader) ReadDouble() (float64, error)
- func (r *Reader) ReadFieldValue() (types.FieldValue, error)
- func (r *Reader) ReadInt() (int, error)
- func (r *Reader) ReadInt16() (int16, error)
- func (r *Reader) ReadMap() (*types.MapValue, error)
- func (r *Reader) ReadNonNilString() (string, error)
- func (r *Reader) ReadPackedInt() (int, error)
- func (r *Reader) ReadPackedLong() (int64, error)
- func (r *Reader) ReadString() (*string, error)
- func (r *Reader) ReadStructValue(v any) error
- func (r *Reader) ReadVersion() (types.Version, error)
- type StructReader
- func (sr *StructReader) DiscardArray() error
- func (sr *StructReader) DiscardMap() error
- func (sr *StructReader) ReadArray(v reflect.Value) error
- func (sr *StructReader) ReadFieldValue(v reflect.Value) error
- func (sr *StructReader) ReadMap(v reflect.Value) error
- func (sr *StructReader) Unmarshal(v any) (err error)
- type UnsupportedTypeError
- type UnsupportedValueError
- type Writer
- func (w *Writer) Bytes() []byte
- func (w *Writer) Reset()
- func (w *Writer) Size() int
- func (w *Writer) Write(p []byte) (n int, err error)
- func (w *Writer) WriteArray(value []types.FieldValue) (n int, err error)
- func (w *Writer) WriteBoolean(value bool) (int, error)
- func (w *Writer) WriteByte(b byte) error
- func (w *Writer) WriteByteArray(value []byte) (n int, err error)
- func (w *Writer) WriteByteArrayWithInt(value []byte) (n int, err error)
- func (w *Writer) WriteCapacityMode(lm types.CapacityMode, serialVersion int16) (int, error)
- func (w *Writer) WriteConsistency(c types.Consistency) (int, error)
- func (w *Writer) WriteDouble(value float64) (int, error)
- func (w *Writer) WriteDurability(c types.Durability, serialVersion int16) (int, error)
- func (w *Writer) WriteFieldRange(fieldRange *types.FieldRange) (n int, err error)
- func (w *Writer) WriteFieldValue(value types.FieldValue) (int, error)
- func (w *Writer) WriteInt(value int) (int, error)
- func (w *Writer) WriteInt16(value int16) (int, error)
- func (w *Writer) WriteIntAtOffset(value int, offset int) (int, error)
- func (w *Writer) WriteMap(value *types.MapValue) (n int, err error)
- func (w *Writer) WriteOpCode(op proto.OpCode) (int, error)
- func (w *Writer) WritePackedInt(value int) (int, error)
- func (w *Writer) WritePackedLong(value int64) (int, error)
- func (w *Writer) WriteSerialVersion(v int16) (int, error)
- func (w *Writer) WriteString(value *string) (n int, err error)
- func (w *Writer) WriteStructValue(value any) (n int, err error)
- func (w *Writer) WriteTTL(ttl *types.TimeToLive) (n int, err error)
- func (w *Writer) WriteTimeout(timeout time.Duration) (int, error)
- func (w *Writer) WriteVersion(version types.Version) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeMapValue ¶ added in v1.4.4
DecodeMapValue decodes the data in an existing MapValue into the given native struct. v must be a pointer to a struct.
func Marshal ¶ added in v1.4.4
Marshal returns the NoSQL "NSON" encoding of v. the NSON encoding is a compact binary format used by most Oracle NoSQL components to transfer record data. This format is only used internally and should not be needed or used outside of the NoSQL SDK code.
Marshal traverses the value v recursively. Marshal uses the following type-dependent default encodings:
Boolean values encode as NoSQL booleans.
Floating point, integer, and [Number] values encode as NoSQL numbers. NaN and +/-Inf values will return an UnsupportedValueError.
String values encode as NoSQL strings.
Array and slice values encode as NoSQL arrays, except that []byte encodes as NoSQL Binary, and a nil slice encodes as the null NoSQL value.
Struct values encode as NoSQL MapValues. Each exported struct field becomes a member of the object, using the field name as the object key, unless the field is omitted for one of the reasons given below.
The encoding of each struct field can be customized by the format string stored under the "nosql" key in the struct field's tag. The format string gives the name of the field, possibly followed by a comma-separated list of options. The name may be empty in order to specify options without overriding the default field name.
The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string.
As a special case, if the field tag is "-", the field is always omitted. Note that a field with name "-" can still be generated using the tag "-,".
Examples of struct field tags and their meanings:
// Field appears in NoSQL as key "myName". Field int `nosql:"myName"` // Field appears in NoSQL as key "myName" and // the field is omitted from the object if its value is empty, // as defined above. Field int `nosql:"myName,omitempty"` // Field appears in NoSQL as key "Field" (the default), but // the field is skipped if empty. // Note the leading comma. Field int `nosql:",omitempty"` // Field is ignored by this package. Field int `nosql:"-"` // Field appears in NoSQL as key "-". Field int `nosql:"-,"`
The "string" option signals that a field is stored as NoSQL inside a NoSQL-encoded string. It applies only to fields of string, floating point, integer, or boolean types. This extra level of encoding is sometimes used when communicating with JavaScript programs:
Int64String int64 `nosql:",string"`
The key name will be used if it's a non-empty string consisting of only Unicode letters, digits, and ASCII punctuation except quotation marks, backslash, and comma.
Embedded struct fields are usually marshaled as if their inner exported fields were fields in the outer struct, subject to the usual Go visibility rules amended as described in the next paragraph. An anonymous struct field with a name given in its NoSQL tag is treated as having that name, rather than being anonymous. An anonymous struct field of interface type is treated the same as having that type as its name, rather than being anonymous.
The Go visibility rules for struct fields are amended for NoSQL when deciding which field to marshal or unmarshal. If there are multiple fields at the same level, and that level is the least nested (and would therefore be the nesting level selected by the usual Go rules), the following extra rules apply:
1) Of those fields, if any are NoSQL-tagged, only tagged fields are considered, even if there are multiple untagged fields that would otherwise conflict.
2) If there is exactly one field (tagged or not according to the first rule), that is selected.
3) Otherwise there are multiple fields, and all are ignored; no error occurs.
Handling of anonymous struct fields is new in Go 1.1. Prior to Go 1.1, anonymous struct fields were ignored. To force ignoring of an anonymous struct field in both current and earlier versions, give the field a NoSQL tag of "-".
Map values encode as NoSQL objects. The map's key type must either be a string or an integer type. The map keys are sorted and used as NoSQL object keys by applying the following rules, subject to the UTF-8 coercion described for string values above:
- keys of any string type are used directly
- integer keys are converted to strings
Pointer values encode as the value pointed to. A nil pointer encodes as the null NoSQL value.
Interface values encode as the value contained in the interface. A nil interface value encodes as the null NoSQL value.
Channel, complex, and function values cannot be encoded in NoSQL. Attempting to encode such a value causes Marshal to return an UnsupportedTypeError.
NoSQL cannot represent cyclic data structures and Marshal does not handle them. Passing cyclic structures to Marshal will result in an error.
func MarshalToWriter ¶ added in v1.4.4
MarshalToWriter does the same as above, but writes to the existing underlying byte buffer in the given Writer.
func UnmarshalFromReader ¶ added in v1.4.4
Types ¶
type InvalidUTF8Error
deprecated
added in
v1.4.4
type InvalidUTF8Error struct {
S string // the whole string value that caused the error
}
Before Go 1.2, an InvalidUTF8Error was returned by Marshal when attempting to encode a string value with invalid UTF-8 sequences. As of Go 1.2, Marshal instead coerces the string to valid UTF-8 by replacing invalid bytes with the Unicode replacement rune U+FFFD.
Deprecated: No longer used; kept for compatibility.
func (*InvalidUTF8Error) Error ¶ added in v1.4.4
func (e *InvalidUTF8Error) Error() string
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads byte sequences from the underlying io.Reader and decodes the bytes to construct in-memory representations according to the Binary Protocol which defines the data exchange format between the Oracle NoSQL Database proxy and drivers.
Reader implements the io.Reader and io.ByteReader interfaces.
func (*Reader) Read ¶
Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.
func (*Reader) ReadArray ¶
func (r *Reader) ReadArray() ([]types.FieldValue, error)
ReadArray reads a structured byte sequences that represent the encoding of an array, decodes the bytes and returns as a slice of types.FieldValue.
func (*Reader) ReadBoolean ¶
ReadBoolean reads and decodes a single byte as a bool value. A zero byte is decoded as false, and any other non-zero byte is decoded as true.
func (*Reader) ReadByteArray ¶
ReadByteArray reads byte sequences and returns as a slice of byte or any error encountered. The returned bytes could be nil.
func (*Reader) ReadByteArrayWithInt ¶
ReadByteArrayWithInt reads byte sequences and returns as a slice of byte or any error encountered. The returned bytes is non-nil.
func (*Reader) ReadDouble ¶
ReadDouble reads and decodes 8 bytes as a float64 value.
func (*Reader) ReadFieldValue ¶
func (r *Reader) ReadFieldValue() (types.FieldValue, error)
ReadFieldValue reads a fixed or variable length of bytes, decodes them as a value of a table field and returns the value or any error encountered.
func (*Reader) ReadMap ¶
ReadMap reads a structured byte sequences that represent the encoding of a Map value, decodes the bytes and returns as an ordered *types.MapValue.
func (*Reader) ReadNonNilString ¶ added in v1.4.0
ReadNonNilString reads a string. If there is an error, it will return an empty string and the error.
func (*Reader) ReadPackedInt ¶
ReadPackedInt reads a variable length of bytes that is an encoding of packed integer, decodes the bytes as an int32 value.
func (*Reader) ReadPackedLong ¶
ReadPackedLong reads a variable length of bytes that is an encoding of packed long value, decodes the bytes as an int64 value.
func (*Reader) ReadString ¶
ReadString reads a variable length of bytes that is an encoding of packed UTF-8 string value, decodes the bytes as a string. It returns a pointer to the string value or any error encountered.
func (*Reader) ReadStructValue ¶ added in v1.4.4
ReadStructValue deserializes data into a native struct. The passed in value must be a pointer to a struct.
type StructReader ¶ added in v1.4.4
type StructReader struct {
// contains filtered or unexported fields
}
StructReader reads byte sequences from the underlying binary.Reader and decodes the bytes to construct native structs according to the Binary Protocol which defines the data exchange format between the Oracle NoSQL Database proxy and drivers.
func NewStructReader ¶ added in v1.4.4
func NewStructReader(b *bytes.Buffer) *StructReader
NewStructReader creates a reader for the binary protocol.
func (*StructReader) DiscardArray ¶ added in v1.4.4
func (sr *StructReader) DiscardArray() error
DiscardArray reads a structured byte sequences that represent the encoding of an array, decodes the bytes and discards them. It is used when skipping over unused or unknown struct fields.
func (*StructReader) DiscardMap ¶ added in v1.4.4
func (sr *StructReader) DiscardMap() error
DisardMap reads and discards a map value. It is used when skipping over unused/unknown fields.
func (*StructReader) ReadArray ¶ added in v1.4.4
func (sr *StructReader) ReadArray(v reflect.Value) error
ReadArray reads a structured byte sequences that represent the encoding of an array, decodes the bytes and puts the values into the given array.
func (*StructReader) ReadFieldValue ¶ added in v1.4.4
func (sr *StructReader) ReadFieldValue(v reflect.Value) error
ReadFieldValue reads a fixed or variable length of bytes, decodes them and sets the result into the passed-in Value
func (*StructReader) ReadMap ¶ added in v1.4.4
func (sr *StructReader) ReadMap(v reflect.Value) error
ReadMap reads a structured byte sequences that represent the encoding of a Map value, and decodes the bytes into the passed-in field, which must be either a struct or a map[string]<specific type>
func (*StructReader) Unmarshal ¶ added in v1.4.4
func (sr *StructReader) Unmarshal(v any) (err error)
type UnsupportedTypeError ¶ added in v1.4.4
An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.
func (*UnsupportedTypeError) Error ¶ added in v1.4.4
func (e *UnsupportedTypeError) Error() string
type UnsupportedValueError ¶ added in v1.4.4
An UnsupportedValueError is returned by Marshal when attempting to encode an unsupported value.
func (*UnsupportedValueError) Error ¶ added in v1.4.4
func (e *UnsupportedValueError) Error() string
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer encodes data into the wire format for the Binary Protocol and writes to a buffer. The Binary Protocol defines the data exchange format between the Oracle NoSQL Database proxy and drivers.
Writer implements the io.Write and io.ByteWriter interfaces.
func (*Writer) WriteArray ¶
func (w *Writer) WriteArray(value []types.FieldValue) (n int, err error)
WriteArray encodes and writes an array of FieldValues to the buffer.
func (*Writer) WriteBoolean ¶
WriteBoolean encodes and writes the bool value to the buffer. A true value is encoded as 1 while a false value is encoded as 0.
func (*Writer) WriteByteArray ¶
WriteByteArray encodes and writes a slice of bytes to the buffer. The slice of bytes could be nil.
func (*Writer) WriteByteArrayWithInt ¶
WriteByteArrayWithInt encodes and writes a slice of bytes to the buffer. The slice of bytes must be non-nil.
func (*Writer) WriteCapacityMode ¶ added in v1.3.0
WriteCapacityMode encodes and writes the limits mode value to the buffer.
func (*Writer) WriteConsistency ¶
func (w *Writer) WriteConsistency(c types.Consistency) (int, error)
WriteConsistency encodes and writes the consistency value to the buffer.
func (*Writer) WriteDouble ¶
WriteDouble encodes and writes the float64 value to the buffer.
func (*Writer) WriteDurability ¶ added in v1.3.0
WriteDurability encodes and writes the Durability value to the buffer.
func (*Writer) WriteFieldRange ¶
func (w *Writer) WriteFieldRange(fieldRange *types.FieldRange) (n int, err error)
WriteFieldRange encodes and writes the FieldRange to the buffer.
func (*Writer) WriteFieldValue ¶
func (w *Writer) WriteFieldValue(value types.FieldValue) (int, error)
WriteFieldValue encodes and writes the specified field value to the buffer.
func (*Writer) WriteInt ¶
WriteInt encodes and writes the int value to the buffer. It assumes the provided value fits into a signed 32-bit integer.
func (*Writer) WriteInt16 ¶
WriteInt16 encodes and writes the int16 value to the buffer.
func (*Writer) WriteIntAtOffset ¶ added in v1.4.0
WriteIntAtOffset encodes and writes the int value to the buffer at a specific offset. It assumes the provided value fits into a signed 32-bit integer.
func (*Writer) WriteOpCode ¶
WriteOpCode encodes and writes the OpCode op to the buffer.
func (*Writer) WritePackedInt ¶
WritePackedInt encodes the int value using packed integer encoding and writes to the buffer. It assumes the provided value fits into a signed 32-bit integer.
func (*Writer) WritePackedLong ¶
WritePackedLong encodes the int64 value using packed long encoding and writes to the buffer.
func (*Writer) WriteSerialVersion ¶
WriteSerialVersion encodes and writes the SerialVersion v to the buffer.
func (*Writer) WriteString ¶
WriteString encodes and writes the string value to the buffer.
func (*Writer) WriteStructValue ¶ added in v1.4.4
func (*Writer) WriteTTL ¶
func (w *Writer) WriteTTL(ttl *types.TimeToLive) (n int, err error)
WriteTTL encodes and writes the TTL value to the buffer.
func (*Writer) WriteTimeout ¶
WriteTimeout encodes and writes the timeout value to the buffer.