Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrInvalidSerializer = errors.New("serializer: invalid serializer type")
)
Functions ¶
func Deserialize ¶
func Deserialize[E any](data []byte, e E, serializer SerializerType) error
Deserializes the provided data using the specified serializer
func Serialize ¶
func Serialize[E any](entity E, serializer SerializerType) ([]byte, error)
Serializes the provided data using the specified serializer
func SerializerExtension ¶
func SerializerExtension(serializer SerializerType) string
Returns the file extension for the provided serializer
Types ¶
type JSONSerializer ¶
type JSONSerializer[E any] struct { Serializer[E] }
func (JSONSerializer[E]) Deserialize ¶
func (js JSONSerializer[E]) Deserialize(data []byte, e any) error
func (JSONSerializer[E]) Extension ¶
func (js JSONSerializer[E]) Extension() string
func (JSONSerializer[E]) Name ¶
func (js JSONSerializer[E]) Name() string
func (JSONSerializer[E]) Serialize ¶
func (js JSONSerializer[E]) Serialize(entity E) ([]byte, error)
func (JSONSerializer[E]) Type ¶
func (js JSONSerializer[E]) Type() SerializerType
type Serializer ¶
type Serializer[E any] interface { Deserialize(data []byte, e any) error Extension() string Name() string Serialize(entity E) ([]byte, error) Type() SerializerType }
Responsible for entity serialization and deserialization
func NewJSONSerializer ¶
func NewJSONSerializer[E any]() Serializer[E]
func NewSerializer ¶
func NewSerializer[T any](st SerializerType) (Serializer[T], error)
Serializer factory method
func NewYAMLSerializer ¶
func NewYAMLSerializer[E any]() Serializer[E]
type SerializerType ¶
type SerializerType int
const ( SERIALIZER_JSON SerializerType = iota SERIALIZER_YAML )
func ParseSerializer ¶
func ParseSerializer(serializer string) (SerializerType, error)
Parses the serializer type from the provided string
func (SerializerType) String ¶
func (s SerializerType) String() string
type YAMLSerializer ¶
type YAMLSerializer[E any] struct { Serializer[E] }
func (YAMLSerializer[E]) Deserialize ¶
func (js YAMLSerializer[E]) Deserialize(data []byte, e any) error
func (YAMLSerializer[E]) Extension ¶
func (js YAMLSerializer[E]) Extension() string
func (YAMLSerializer[E]) Name ¶
func (js YAMLSerializer[E]) Name() string
func (YAMLSerializer[E]) Serialize ¶
func (js YAMLSerializer[E]) Serialize(entity E) ([]byte, error)
func (YAMLSerializer[E]) Type ¶
func (js YAMLSerializer[E]) Type() SerializerType
Click to show internal directories.
Click to hide internal directories.