Documentation
¶
Index ¶
- type DefaultTagSerializer
- type Deserializer
- type DeserializerFunc
- type ETPolySerializer
- type PolyDeserializer
- type PolySerializer
- type PrefixPolySerializer
- type STPolySerializer
- type Serializer
- type SerializerFunc
- type TagDeserializer
- type TagNotFoundError
- type TagRegisterError
- type TagSerializer
- type TagTypeResgistry
- type TypeNotFoundError
- type TypeTag
- type TypeTagTypeError
- type UnsupportedTypeError
- type UnsupportedValueError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultTagSerializer ¶
type DefaultTagSerializer struct { Serializer Serializer Deserializer Deserializer TagTypeResgistry *TagTypeResgistry }
DefaultTagSerializer is default implementation of TagSerializer and TagDeserializer.
func (*DefaultTagSerializer) Deserialize ¶
func (ds *DefaultTagSerializer) Deserialize(data []byte, tt TypeTag) (res interface{}, err error)
func (*DefaultTagSerializer) GetTypeTag ¶
func (ds *DefaultTagSerializer) GetTypeTag(data interface{}) (tt TypeTag, err error)
func (*DefaultTagSerializer) Serialize ¶
func (ds *DefaultTagSerializer) Serialize(event interface{}) (res []byte, err error)
type Deserializer ¶
Deserializer, which fits most interfaces exposed by golang already. For instance, json.Unmarshal with SerializerFunc.
type DeserializerFunc ¶
func (DeserializerFunc) Deserialize ¶
func (f DeserializerFunc) Deserialize(data []byte, dst interface{}) (err error)
type ETPolySerializer ¶
type ETPolySerializer struct { Serializer Serializer Deserializer Deserializer TagTypeResgistry *TagTypeResgistry }
ETPolySerializer uses external field called `type`. Actual data is stored in `data` json field. This approach is known as adjacent tagging in most(?) serialization frameworks(for instance serde_json). It works with serializers like JSON one build in golang stdlib.
Note: in order for this to work deserializer must accept unknown fields in data, otherwise it won't work. Note#2: It's implementation is somwhat magic and it's expected to work only against JSON serializer in go stdlib. No unit testing is performed against any other serialization implementation.
func (*ETPolySerializer) PolyDeserialize ¶
func (ets *ETPolySerializer) PolyDeserialize(data []byte) (res interface{}, err error)
func (*ETPolySerializer) PolySerialize ¶
func (ets *ETPolySerializer) PolySerialize(data interface{}) (res []byte, err error)
type PolyDeserializer ¶
PolyDeserializer handles polymprphic deserialization without any external hints about type of data deserialized provided by caller.
Note: This deserializer always returns struct values rather than pointer values.
type PolySerializer ¶
PolySerializer handles polymorphic serialization without any external hints about type of data serialized.
type PrefixPolySerializer ¶
type PrefixPolySerializer struct { TypeTagSerializer PolySerializer TypeTagDeserializer PolyDeserializer DataSerializer TagSerializer DataDeserializer TagDeserializer }
PrefixPolySerializer serializes and stores tag as prefix in result byte slice in order to mix tag along with data stored with it.
It adds minimal overhead to serialized data. When tag is shorter than 127 bytes then only one additional byte(apart from tag) is added to serialized data.
func (*PrefixPolySerializer) PolyDeserialize ¶
func (pps *PrefixPolySerializer) PolyDeserialize(data []byte) (res interface{}, err error)
func (*PrefixPolySerializer) PolySerialize ¶
func (pps *PrefixPolySerializer) PolySerialize(data interface{}) (res []byte, err error)
type STPolySerializer ¶
type STPolySerializer struct { Type reflect.Type Serializer Serializer Deserializer Deserializer }
STPolySerializer is poly serializer and deserializer, which is able to serialize only single type.
func (*STPolySerializer) PolyDeserialize ¶
func (ser *STPolySerializer) PolyDeserialize(data []byte) (res interface{}, err error)
func (*STPolySerializer) PolySerialize ¶
func (ser *STPolySerializer) PolySerialize(data interface{}) (res []byte, err error)
type Serializer ¶
Serializer, which fits most interfaces exposed by golang already. For instance, json.Marshal with SerializerFunc.
type SerializerFunc ¶
func (SerializerFunc) Serialize ¶
func (f SerializerFunc) Serialize(data interface{}) (res []byte, err error)
type TagDeserializer ¶
type TagDeserializer interface {
Deserialize(data []byte, tag TypeTag) (res interface{}, err error)
}
TagDeserializer uses tag and data in order to deserialize actual type.
Note: This deserializer always returns struct pointers rather than struct values.
type TagNotFoundError ¶
func (*TagNotFoundError) Error ¶
func (e *TagNotFoundError) Error() string
type TagRegisterError ¶
func (*TagRegisterError) Error ¶
func (e *TagRegisterError) Error() string
type TagSerializer ¶
type TagSerializer interface { GetTypeTag(data interface{}) (tt TypeTag, err error) Serialize(data interface{}) (res []byte, err error) }
TagSerializer uses external information(so called tag) to make polymorphic marshalling work.
type TagTypeResgistry ¶
type TagTypeResgistry struct {
// contains filtered or unexported fields
}
TagTypeResgistry maps type to type tag and vice versa.
func NewTagTypeResgistry ¶
func NewTagTypeResgistry(tagType reflect.Type) *TagTypeResgistry
NewTagTypeResgistry creates new tag type registry accepting tags with specified type.
func (*TagTypeResgistry) GetTag ¶
func (ttr *TagTypeResgistry) GetTag(ty reflect.Type) (tt TypeTag, err error)
func (*TagTypeResgistry) GetType ¶
func (ttr *TagTypeResgistry) GetType(tt TypeTag) (ty reflect.Type, err error)
func (*TagTypeResgistry) GetTypeTagType ¶
func (ttr *TagTypeResgistry) GetTypeTagType() reflect.Type
GetTypeTagType returns type of type tags used in this registry.
func (*TagTypeResgistry) RegisterType ¶
func (ttr *TagTypeResgistry) RegisterType(ty reflect.Type, et TypeTag) (err error)
Registers specified type, so that it can be deserialized using specified type tag.
type TypeNotFoundError ¶
type TypeNotFoundError struct {
TypeTag TypeTag
}
func (*TypeNotFoundError) Error ¶
func (e *TypeNotFoundError) Error() string
type TypeTagTypeError ¶
func (*TypeTagTypeError) Error ¶
func (e *TypeTagTypeError) Error() string
type UnsupportedTypeError ¶
func (*UnsupportedTypeError) Error ¶
func (ute *UnsupportedTypeError) Error() string
type UnsupportedValueError ¶
type UnsupportedValueError struct {
Val interface{}
}
func (*UnsupportedValueError) Error ¶
func (uve *UnsupportedValueError) Error() string