Documentation
¶
Index ¶
- Constants
- Variables
- func ObjectSliceToBytes(objects ObjectList, writer Writer) ([]byte, *gopolutils.Exception)
- func ObjectToBytes(object Object, writer Writer) ([]byte, *gopolutils.Exception)
- func SliceToView[Type any](items []Type) collections.View[Type]
- type Object
- type ObjectList
- type Reader
- type Serializer
- func (serializer Serializer[Type]) ReadList(data ObjectList) (collections.View[Type], *gopolutils.Exception)
- func (serializer Serializer[Type]) ReadObject(data Object) (*Type, *gopolutils.Exception)
- func (serializer Serializer[Type]) WriteList(data collections.View[Type]) (ObjectList, *gopolutils.Exception)
- func (serializer Serializer[Type]) WriteObject(data Type) (Object, *gopolutils.Exception)
- type Writer
Constants ¶
const ( MarshalError gopolutils.ExceptionName = "MarshalError" UnmarshalError gopolutils.ExceptionName = "UnmarshalError" )
Variables ¶
var ( // Default json reader. JSONReader Reader = json.Unmarshal // Default yaml reader. YAMLReader Reader = yaml.Unmarshal // Default toml reader. TOMLReader Reader = toml.Unmarshal // Default csv reader. CSVReader Reader = csv.Unmarshal // Default json writer. JSONWriter Writer = json.Marshal // Indented writer for json types. The indent is based on tabs instead of spaces. JSONIndentWriter Writer = jsonIndentWriter("\t") // Default yaml writer. YAMLWriter Writer = yaml.Marshal // Default toml writer. TOMLWriter Writer = toml.Marshal // Default csv writer. CSVWriter Writer = csv.Marshal )
Functions ¶
func ObjectSliceToBytes ¶ added in v0.4.0
func ObjectSliceToBytes(objects ObjectList, writer Writer) ([]byte, *gopolutils.Exception)
Convert a slice of objects to a stream of bytes. Returns a stream of bytes representing the slice of objects. If the slice of objects can not be marshalled, a MarshallError is returned with a nil data pointer.
func ObjectToBytes ¶ added in v0.4.0
func ObjectToBytes(object Object, writer Writer) ([]byte, *gopolutils.Exception)
Convert an object type to a stream of bytes. Returns a byte slice representing the object. If the object can not be marshalled, a MarshallError is returned with a nil data pointer.
func SliceToView ¶ added in v0.2.0
func SliceToView[Type any](items []Type) collections.View[Type]
Convert a slice into a concurrent-safe collections.View. Returns a new concurrent-safe collections.View containing the elements of the given slice.
Types ¶
type Object ¶
Serializable map object type alias.
func BytesToObject ¶ added in v0.2.0
func BytesToObject(content []byte, reader Reader) (Object, *gopolutils.Exception)
Convert a stream of bytes to an object type. Returns an object type representing the stream of bytes. If the stream of bytes can not be unmarshalled, an UnmarshalError is returned with a nil data pointer.
type ObjectList ¶ added in v0.8.0
type ObjectList []Object
Slice of serializable objects.
func BytesToObjectSlice ¶ added in v0.4.0
func BytesToObjectSlice(content []byte, reader Reader) (ObjectList, *gopolutils.Exception)
Convert a stream of bytes to a slice of objects. Returns a slice of objects representing the stream of bytes. If the stream of bytes can not be marshalled, a MarshalError is returned with a nil data pointer.
type Reader ¶
Generic unmarshal type. The reader type takes in the raw byte content and a pointer to the object.
type Serializer ¶ added in v0.2.0
type Serializer[Type any] struct { // contains filtered or unexported fields }
A simple serializer.
func NewSerializer ¶ added in v0.2.0
func NewSerializer[Type any](reader Reader, writer Writer) *Serializer[Type]
Construct a new serializer. Returns a pointer to a new serializer of a given type with a given reader and writer.
? This function could probably be renamed in the future to make use of the domain since this is the main entry point of the library and no other constructors are defined at the moment.
func (Serializer[Type]) ReadList ¶ added in v0.3.0
func (serializer Serializer[Type]) ReadList(data ObjectList) (collections.View[Type], *gopolutils.Exception)
Serialize a slice of objects into a typed view. Returns a reflected type view. If the given data can not be reflected, either writing or reading, an appropriate error is returned with a nil data pointer.
func (Serializer[Type]) ReadObject ¶ added in v0.3.0
func (serializer Serializer[Type]) ReadObject(data Object) (*Type, *gopolutils.Exception)
Serialize an object into a type pointer. Returns a reflected type pointer. If the given data can not be reflected, either writing or reading, an appropriate error is returned with a nil data pointer.
func (Serializer[Type]) WriteList ¶ added in v0.3.0
func (serializer Serializer[Type]) WriteList(data collections.View[Type]) (ObjectList, *gopolutils.Exception)
Serialize a slice of objects into a typed view. Returns a reflected object slice. If the given data can not be reflected, either writing or reading, an appropriate error is returned with a nil data pointer.
func (Serializer[Type]) WriteObject ¶ added in v0.3.0
func (serializer Serializer[Type]) WriteObject(data Type) (Object, *gopolutils.Exception)
Serialize a given data type as an object. Returns an object with the reflected type properties. If the given data can not be reflected, either writing or reading, an appropriate error is returned with a nil data pointer.