Metadata-Version: 2.1
Name: serialise
Version: 0.0.0
Summary: A project to allow serialising and deserialising python objects
Author: RJ_Infinity
License: MIT License
        
        Copyright (c) 2024 RJ_Infinity
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/RJ-Infinity/serialise
Project-URL: Documentation, https://github.com/RJ-Infinity/serialise
Project-URL: Repository, https://github.com/RJ-Infinity/serialise
Project-URL: Issues, https://github.com/RJ-Infinity/serialise/issues
Keywords: serialiser,serialisation,deserialiser,deserialisation,binary,format,saving
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE

# serialise

this is a simple library to serialise and deserialise python
objects. it can serialise any object given it has a serialiser
written for it. Many python builtins already have serialisers

to create a serialiser you use the Serialiser class

here is an example (the default list serialiser but more friendly)
```py
from serialiser import Serialiser, read_size, write_size, serialise, deserialise
from io import BytesIO
def list_serialiser(data: list)->bytes:
	# create a bytearray this is a more convient way of creating bytes
	rv = bytearray()
	# add the length of the list
	# write size writes an int
	rv.extend(write_size(len(data)))
	# for each element in the list add the serialised element
	for el in data: rv.extend(serialise(el))
	return bytes(rv)
def list_deserialiser(data: bytes)->list:
	# the serialiser in reverse
	# create a BytesIO which is a more convient way of reading bytes
	data = BytesIO(data)
	# first read the length
	length = read_size(data, "list length")
	# then deserialise length elements from the data and reutrn them in an array
	return [deserialise(data) for _ in range(length)]
# register the Serialiser by createing a new instance of the Serialiser class
Serialiser(
	list,
	list_serialiser,
	list_deserialiser
)
```
