Documentation
¶
Index ¶
- Constants
- Variables
- func AvroDate(t time.Time) time.Time
- func AvroTime(t time.Time) time.Time
- func DecodeMagic(data []byte) (NamespaceID, SchemaID, CompressionID, 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 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 4 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") 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") 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 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 It also makes sure that the time is expressed in UTC()
func DecodeMagic ¶
func DecodeMagic(data []byte) (NamespaceID, SchemaID, CompressionID, 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 UnmarshalBasic ¶
func UnmarshalInt ¶
func UnmarshalSchemer ¶
UnmarshalUnion expects a slice with preallocated 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
AVSC 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
AVSC 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
AVSC 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 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
AVSC 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.ficed) BasicDecimalSchemaID SchemaID = 6<<8 + 1 )
func PackSchemVer ¶
type Schemer ¶
type Schemer interface {
NamespaceID() NamespaceID
SchemaID() SchemaID
Schema() string
}