# Bytes Argument Serializer

## BAS Object
```python
from byarse import BAS


bas = BAS(
	safe=True, # Enable/disable safe mode. Safe mode prevents Pickle objects from being deserialized! (enabled by default)
)
```

## Serialize
```python
serialized = bas.s([
	'Hello, world!', # string
	b'Hello, world!', # bytes
	42, # int
	2.5, # float
	datetime.datetime.utcnow(), # datetime
]) # b'...'
```

## Deserialize
```python
data = bas.u(
	serialized
)
```

## Pickle
You can have anything Pickleable be pickled and unpickled automatically by Byarse.
Pickle can be potentially dangerous, so try not to avoid it, or sign and verify all serializations with something like HMAC!
Safe mode must be set to `False` for pickled objects to be deserialized.

```python
class Test:
	a = 1

serialized bas.s([
	Pickle(Test)
]) # b'...'

self.safe = False

bas.u(serialized) # <class 'Test'>

self.safe = True

bas.u(serialized) # raises TypeError
```

## Example Program

```python
import os, datetime
from byarse import Pickle
from byarse import BAS


bas = BAS(safe=True) # Serializer/Deserializer


class Test: # Test class (for pickling)
    randomdata = os.urandom(16)


i = input("Read or write? (r/w)\n")


if i.lower().startswith('w'): # 'w'
    # ----
    # Serialize
    # ----
    with open('test', 'wb') as f:
        f.write(bas.s([
            'Hello, world!',
            b'Hello, world!',
            42,
            2.5,
            datetime.datetime.utcnow(),
            # Pickle(Test) # Will raise TypeError when read if safe mode is enabled.
        ]))
else: # 'r'
    # ----
    # Deserialize
    # ----
    with open('test', 'rb') as f:
        ua = bas.u(f.read()) # Unserialize

        for i in ua:
            print(type(i).__name__, ':', i) # Output: "type : argument" (ex. str : Hello, world!)
```
