Documentation ¶
Index ¶
- Constants
- Variables
- func AvroDate(t time.Time) time.Time
- func AvroTime(t time.Time) time.Time
- func CompressData(data []byte, cID CompressionID) ([]byte, error)
- func DecodeMagic(data []byte) (NamespaceID, SchemaID, CompressionID, error)
- func DecompressData(data []byte, cID CompressionID) ([]byte, error)
- func IsMagic(data []byte) bool
- func JoinedSchemas(schemers ...Schemer) string
- func Marshal(src Schemer, cID CompressionID, schema avro.Schema) ([]byte, error)
- func MarshalAny(src any, schema avro.Schema, nID NamespaceID, sID SchemaID, cID CompressionID) ([]byte, error)
- func MarshalBasic(src any, cID CompressionID) ([]byte, error)
- func Unmarshal(data []byte, dst Schemer, schema avro.Schema) error
- func UnmarshalAny[T any](data []byte, schema avro.Schema, dst *T) (NamespaceID, SchemaID, error)
- func UnmarshalBasic(src []byte) (any, error)
- func UnmarshalInt(data []byte) (int, error)
- func UnmarshalSchemer(src []byte, schemers ...Schemer) (any, error)
- func UnmarshalString(data []byte) (string, error)
- func UnpackSchemVer(schemaVerID SchemaID) (int, int)
- type BasicByteSlice
- type BasicDecimal
- type BasicInt
- type BasicMapStringAny
- type BasicRawDate
- type BasicString
- type BasicTime
- type CompressionID
- type Magic
- func EncodeMagic(namespace NamespaceID, schema SchemaID, compression CompressionID) (Magic, error)
- func EncodePrivateMagic(compression CompressionID) (Magic, error)
- func MustEncodeBasicMagic(schemaID SchemaID, compression CompressionID) Magic
- func MustEncodePrivateMagic(compression CompressionID) Magic
- type NamespaceID
- type SchemaID
- type Schemer
Constants ¶
const ( CompNone CompressionID = 0 CompSnappy CompressionID = 1 CompFlate CompressionID = 2 // Uses -1 as compression parameter CompGZip CompressionID = 3 // Uses -1 as compression parameter CompMax CompressionID = 255 // NamespacePrivate means that it is not registered and we use private schemas NamespacePrivate NamespaceID = 0 // NamespaceBasic is reserved for the basic types and structs that are implemented through avrox NamespaceBasic NamespaceID = 1 // NamespaceReserved1 is reserved for later NamespaceReserved1 NamespaceID = 2 // NamespaceReserved2 is reserved for later NamespaceReserved2 NamespaceID = 3 // NamespaceReserved3 is reserved for later NamespaceReserved3 NamespaceID = 4 NamespaceMax NamespaceID = 65535 // Schema 0 means that it is not defined (but may belong to a namespace) SchemaUndefined SchemaID = 0 SchemaMax SchemaID = 16777215 // Schema<<8 | Version MagicFieldName = "Magic" )
const MagicLen = 8 // The struct will be aligned to 8 bytes anyway
Variables ¶
var ( ErrLengthInvalid = errors.New("data length should be exactly 8 bytes") ErrNamespaceIDOutOfRange = errors.New("namespace must be between 0 and 31") ErrCompressionIDOutOfRange = errors.New("compression must be between 0 and 7") ErrCompressionUnsupported = errors.New("compression type is unsupported") ErrSchemaIDOutOfRange = errors.New("schema must be between 0 and 8191") ErrMarkerInvalid = fmt.Errorf("data should start with magic marker (0x%02x)", Marker) ErrParityCheckFailed = errors.New("parity check failed") ErrMarshallingFailed = errors.New("marshalling failed") ErrMissingMagicField = errors.New("missing magic field in struct") ErrMarshallAnyWithoutPtr = errors.New("no ptr src for MarshalAny") ErrSchemaNil = errors.New("schema is nil") ErrSchemaInvalid = errors.New("schema is invalid") ErrDecompress = errors.New("can not decompress") ErrDataFormatNotDetected = errors.New("message format was not detected") ErrNoData = errors.New("no data") ErrNoBasicNamespace = errors.New("no basic namespace") ErrNoBasicSchema = errors.New("no basic schema") ErrNoBasicString = errors.New("no basic string") ErrNoBasicInt = errors.New("no basic int") ErrNoBasicByteSlice = errors.New("no basic byte slice") ErrNoBasicMapStringAny = errors.New("no basic map string any") ErrNoBasicTime = errors.New("no basic time") ErrNoBasicRawDate = errors.New("no basic rawdate") ErrNoBasicDecimal = errors.New("no basic decimal") ErrWrongNamespace = errors.New("namespace from schemer does not fit the magic entry") ErrWrongSchema = errors.New("schema from schemer does not fit the magic entry") ErrNotAvroX = errors.New("data is not avrox") ErrNoPointerDestination = errors.New("not a pointer destination") ErrSchemerNotFound = errors.New("schema from schemer is not in the given slice") )
var BasicByteSliceAVSC string
var BasicDecimalAVSC string
var BasicIntAVSC string
var BasicMapStringAnyAVSC string
var BasicRawDateAVSC string
var BasicStringAVSC string
var BasicTimeAVSC string
var Marker byte = 0x93 // one of the best when analysing our data
Functions ¶
func AvroDate ¶
AvroDate truncates a go time.Time to the value that gets stored the avro logicalDate It also makes sure that the time is expressed in UTC()
func AvroTime ¶
AvroTime truncates a go time.Time to the value that gets stored the avro logicalTime (which has a granularity of milliseconds while go has nanoseconds) It also makes sure that the time is expressed in UTC()
func CompressData ¶ added in v0.1.0
func CompressData(data []byte, cID CompressionID) ([]byte, error)
func DecodeMagic ¶
func DecodeMagic(data []byte) (NamespaceID, SchemaID, CompressionID, error)
func DecompressData ¶ added in v0.1.0
func DecompressData(data []byte, cID CompressionID) ([]byte, error)
func JoinedSchemas ¶
JoinedSchemas returns a json array of all schemers in the arguments
func MarshalAny ¶
func MarshalAny(src any, schema avro.Schema, nID NamespaceID, sID SchemaID, cID CompressionID) ([]byte, error)
func MarshalBasic ¶
func MarshalBasic(src any, cID CompressionID) ([]byte, error)
func Unmarshal ¶
Unmarshal uses the give schema for unmarshalling and checks if it fits to the decode data. This function is faster if the schema is given When the schema is not given it will parse the Schemer info. If the schema is given, it will check that this matches to the Schemer info
func UnmarshalAny ¶
func UnmarshalAny[T any](data []byte, schema avro.Schema, dst *T) (NamespaceID, SchemaID, error)
func UnmarshalBasic ¶
func UnmarshalInt ¶
func UnmarshalSchemer ¶
UnmarshalSchemer expects a slice with pre-allocated schemers and uses the magic in the data to unmarshal the correct one. It will return the used schema as any If no schema fits it will return an error
func UnmarshalString ¶
func UnpackSchemVer ¶
Types ¶
type BasicByteSlice ¶
func (BasicByteSlice) NamespaceID ¶
func (BasicByteSlice) NamespaceID() NamespaceID
NamespaceID returns the namespace id for the BasicInt struct type
func (BasicByteSlice) Schema ¶
func (BasicByteSlice) Schema() string
Schema returns the AVRO schema for the BasicString struct type
func (BasicByteSlice) SchemaID ¶
func (BasicByteSlice) SchemaID() SchemaID
SchemaID returns the schema id for the BasicInt struct type
type BasicDecimal ¶
BasicDecimal is the container type to store a *bigRat value into a single avro schema
func (BasicDecimal) NamespaceID ¶
func (BasicDecimal) NamespaceID() NamespaceID
NamespaceID returns the namespace id for the BasicDecimal struct type
func (BasicDecimal) Schema ¶
func (BasicDecimal) Schema() string
Schema returns the AVRO schema for the BasicDecimal struct type
func (BasicDecimal) SchemaID ¶
func (BasicDecimal) SchemaID() SchemaID
SchemaID returns the schema id for the BasicDecimal struct type
type BasicInt ¶
func (BasicInt) NamespaceID ¶
func (BasicInt) NamespaceID() NamespaceID
NamespaceID returns the namespace id for the BasicInt struct type
type BasicMapStringAny ¶
func (BasicMapStringAny) NamespaceID ¶
func (BasicMapStringAny) NamespaceID() NamespaceID
NamespaceID returns the namespace id for the BasicInt struct type
func (BasicMapStringAny) Schema ¶
func (BasicMapStringAny) Schema() string
Schema returns the AVRO schema for the BasicString struct type
func (BasicMapStringAny) SchemaID ¶
func (BasicMapStringAny) SchemaID() SchemaID
SchemaID returns the schema id for the BasicInt struct type
type BasicRawDate ¶ added in v0.3.0
BasicRawDate is the container type to store a timestamp in a single avro schema
func (BasicRawDate) NamespaceID ¶ added in v0.3.0
func (BasicRawDate) NamespaceID() NamespaceID
NamespaceID returns the namespace id for the BasicRawDate struct type
func (BasicRawDate) Schema ¶ added in v0.3.0
func (BasicRawDate) Schema() string
Schema returns the AVRO schema for the BasicRawDate struct type
func (BasicRawDate) SchemaID ¶ added in v0.3.0
func (BasicRawDate) SchemaID() SchemaID
SchemaID returns the schema id for the BasicRawDate struct type
type BasicString ¶
BasicString is the container type to store a string in a single avro schema
func (BasicString) NamespaceID ¶
func (BasicString) NamespaceID() NamespaceID
NamespaceID returns the namespace id for the BasicString struct type
func (BasicString) Schema ¶
func (BasicString) Schema() string
Schema returns the AVRO schema for the BasicString struct type
func (BasicString) SchemaID ¶
func (BasicString) SchemaID() SchemaID
SchemaID returns the schema id for the BasicString struct type
type BasicTime ¶
BasicTime is the container type to store a timestamp in a single avro schema
func (BasicTime) NamespaceID ¶
func (BasicTime) NamespaceID() NamespaceID
NamespaceID returns the namespace id for the BasicTime struct type
type CompressionID ¶
type CompressionID int
type Magic ¶
func EncodeMagic ¶
func EncodeMagic(namespace NamespaceID, schema SchemaID, compression CompressionID) (Magic, error)
func EncodePrivateMagic ¶
func EncodePrivateMagic(compression CompressionID) (Magic, error)
func MustEncodeBasicMagic ¶
func MustEncodeBasicMagic(schemaID SchemaID, compression CompressionID) Magic
func MustEncodePrivateMagic ¶
func MustEncodePrivateMagic(compression CompressionID) Magic
type NamespaceID ¶
type NamespaceID int
type SchemaID ¶
type SchemaID int // Schema<<8 | 8 bit version
const ( // BasicStringSchemaID is the id for the avro schema of struct BasicString BasicStringSchemaID SchemaID = 1<<8 + 1 // BasicIntSchemaID is the id for the avro schema of struct BasicInt BasicIntSchemaID SchemaID = 2<<8 + 1 // BasicByteSliceSchemaID is the id for the avro schema of struct BasicInt BasicByteSliceSchemaID SchemaID = 3<<8 + 1 // BasicMapStringAnySchemaID is the id for the avro schema of struct BasicMapStringAny BasicMapStringAnySchemaID SchemaID = 4<<8 + 1 // BasicTimeSchemaID is the id for the avro schema of struct BasicTime BasicTimeSchemaID SchemaID = 5<<8 + 1 // BasicDecimalSchemaID is the id for the avro schema of struct BasicDecimal (*big.Rat / decimal.fixed) BasicDecimalSchemaID SchemaID = 6<<8 + 1 // BasicRawDateSchemaID is the id for the avro schema of struct BasicRawDate (rawdate.Rawdate) BasicRawDateSchemaID SchemaID = 7<<8 + 1 )
func PackSchemVer ¶
type Schemer ¶
type Schemer interface { NamespaceID() NamespaceID SchemaID() SchemaID Schema() string }
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
nats
|
|
Package rawdate provides a simple date handling utility without time.
|
Package rawdate provides a simple date handling utility without time. |