Name | canoser JSON |
Version |
0.8.2
JSON |
| download |
home_page | https://github.com/yuan-xy/canoser-python.git |
Summary | A python implementation of the LCS(Libra Canonical Serialization) for the Libra network. |
upload_time | 2020-04-02 04:15:39 |
maintainer | |
docs_url | None |
author | yuan xinyu |
requires_python | >=3.6 |
license | |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
A python implementation of the canonical serialization for the Libra network.
Canonical serialization guarantees byte consistency when serializing an in-memory
data structure. It is useful for situations where two parties want to efficiently compare
data structures they independently maintain. It happens in consensus where
independent validators need to agree on the state they independently compute. A cryptographic
hash of the serialized data structure is what ultimately gets compared. In order for
this to work, the serialization of the same data structures must be identical when computed
by independent validators potentially running different implementations
of the same spec in different languages.
## Installation
Require python 3.6 or above installed.
```sh
$ python3 -m pip install canoser
```
## Usage
First define a data structure with Canoser, that is, write a class that inherits from "canoser.Struct", and then define the fields owned by the structure through the "\_fields" array. This structure naturally has the ability to canonical serialize and deserialize types. For example, the following AccountResource defines a data structure of the same name in the Libra code:
```python
#python code,define canoser data structure
from canoser import Struct, Uint8, Uint64
class AccountResource(Struct):
_fields = [
('authentication_key', [Uint8]),
('balance', Uint64),
('delegated_withdrawal_capability', bool),
('received_events', EventHandle),
('sent_events', EventHandle),
('sequence_number', Uint64)
]
```
Here is the code that defines this data structure and serialization in Libra code:
```rust
// rust code in Libra
// define the data structure
pub struct AccountResource {
balance: u64,
sequence_number: u64,
authentication_key: ByteArray,
sent_events: EventHandle,
received_events: EventHandle,
delegated_withdrawal_capability: bool,
}
// serialization
impl CanonicalSerialize for AccountResource {
fn serialize(&self, serializer: &mut impl CanonicalSerializer) -> Result<()> {
serializer
.encode_struct(&self.authentication_key)?
.encode_u64(self.balance)?
.encode_bool(self.delegated_withdrawal_capability)?
.encode_struct(self.received_events)?
.encode_struct(self.sent_events)?
.encode_u64(self.sequence_number)?;
Ok(())
}
}
```
~~In the rust language used by Libra, it is necessary to manually write code to serialize/deserialize the data structure, and the order of the fields in the data structure and the order of serialization are not necessarily the same.~~
In Canoser, after defining the data structure, you don't need to write code to implement serialization and deserialization. Note that the order of the data structures in Canoser is defined in the order in which they are serialized in Libra.
### Supported field types
| field type | optionl sub type | description |
| ------ | ------ | ------ |
| canoser.Uint8 | | Unsigned 8-bit integer |
| canoser.Uint16 | | Unsigned 16-bit integer|
| canoser.Uint32 | | Unsigned 32-bit integer |
| canoser.Uint64 | | Unsigned 64-bit integer |
| canoser.Uint128 | | Unsigned 128-bit integer |
| canoser.Int8 | | Signed 8-bit integer |
| canoser.Int16 | | Signed 16-bit integer|
| canoser.Int32 | | Signed 32-bit integer |
| canoser.Int64 | | Signed 64-bit integer |
| canoser.Int128 | | Signed 128-bit integer |
| bool | | Boolean |
| str | | String |
| bytes | | Binary String |
| [] | supported | Array Type |
| {} | supported | Map Type |
| () | supported | Tuple Type |
| canoser.Struct | | Another structure nested (cannot be recycled) |
| RustEnum | | Enum type |
| RustOptional | | Optional type |
### About Array Type
The default data type (if not defined) in the array is Uint8. The following two definitions are equivalent:
```python
class Arr1(Struct):
_fields = [(addr, [])]
class Arr2(Struct):
_fields = [(addr, [Uint8])]
```
Arrays can also define lengths to represent fixed length data. For example, the address in Libra is 256 bits, which is 32 bytes, so it can be defined as follows:
```python
class Address(Struct):
_fields = [(addr, [Uint8, 32])]
```
When the fixed length data is serialized, you can skip the length information written to the output. For example, following code will generate 32 bytes without writing the length of the addr during serialization.
```python
class Address(Struct):
_fields = [(addr, [Uint8, 32, False])]
```
### About map type
The default data type (if not defined) in the map is an array of Uint8 in Libra, both of key and value.
But the python language dosn't support the array data type to be the key of a dict, so we change the key type from array of Uint8 to bytes in python, the type of value is unchanged.
The following two definitions are equivalent:
```python
class Map1(Struct):
_fields = [(addr, {})]
class Map2(Struct):
_fields = [(addr, {bytes : [Uint8] })]
```
### About enum type
In python and C, enum is just enumerated constants. But in Libra(Rust), a enum has a type constant and a optional Value. A rust enumeration is typically represented as:
```
enum SomeDataType {
type0(u32),
type1(u64),
type2
}
```
To define a enum with Canoser, first write a class that inherits from "canoser.RustEnum", and then define the types owned by the enum through the "\_enums" array.
For example, the following TransactionArgument defines a data structure of the same name in the Libra code. The argument of a transaction can be one of the four types: Uint64 or Address or String or IntArray.:
```python
class TransactionArgument(RustEnum):
_enums = [
('U64', Uint64),
('Address', [Uint8, ADDRESS_LENGTH]),
('String', str),
('ByteArray', [Uint8])
]
```
You can instantiate an enum obj and call its method and properties like this:
```python
arg2 = TransactionArgument('String', 'abc')
assert arg2.index == 2
assert arg2.value == 'abc'
assert arg2.String == True
assert arg2.U64 == False
```
Every RustEnum object has an `index` property and a `value` property. After instantiated, the `index` can't be modified. You can only modify the `value` of an enum with correct data type.
For example, the following code is valid:
```python
arg2 = TransactionArgument('String', 'abc')
arg2.value == 'Bcd'
```
For example, the following code is invalid:
```python
arg2.index = 0 #raise an exception
arg2.value = [3] #raise an exception
```
The RustEnum can have a enum without value type, which represented by `None`.
```python
class Enum1(RustEnum):
_enums = [('opt1', [Uint8]), ('opt2', None)]
e2 = Enum1('opt2', None)
#or
e2 = Enum1('opt2')
```
You can also instantiate a RustEnum object by index and value.
```python
e1 = Enum1.new(0, [5])
# which is equivalent to
e1 = Enum1('opt1', [5])
```
### About optional type
An optional type in libra is a nullable data either exists in its full representation or does not. For example,
```
optional_data: Option(uint8); // Rust/Libra
uint8 *optional_data; // C
```
It has similar semantics meaning with the following enum type:
```
enum Option<uint8> {
Some(uint8),
None,
}
```
To define a optional with Canoser, first write a class that inherits from "canoser.RustOptional", and then define the types owned by RustOptional through the "\_type" field. For example,
```python
class OptionUInt(RustOptional):
_type = Uint8
null = OptionUInt(None)
obj = OptionUInt(8)
assert obj.value == 8
```
Here's a complete example:
```python
class OptionStr(RustOptional):
_type = str
class OptionTest(Struct):
_fields = [
('message', OptionStr)
]
def __init__(self, msg=None):
if msg is not None:
self.message = OptionStr(msg)
else:
self.message = OptionStr(None)
test = OptionTest('test_str')
assert test.message.value == 'test_str'
```
The RustOptional type in canoser is similar to `typing.Optional` in python. Note that this is not the same concept as an optional argument, which is one that has a default.
### Nested data structure
The following is a complex example with three data structures:
```python
class Addr(Struct):
_fields = [('addr', [Uint8, 32])]
class Bar(Struct):
_fields = [
('a', Uint64),
('b', [Uint8]),
('c', Addr),
('d', Uint32),
]
class Foo(Struct):
_fields = [
('a', Uint64),
('b', [Uint8]),
('c', Bar),
('d', bool),
('e', {}),
]
```
This example refers to the test code from canonical serialization in libra.
### Serialization and deserialization
After defining canoser.Struct, you don't need to implement serialization and deserialization code yourself, you can directly call the default implementation of the base class. Take the AccountResource structure as an example:
```python
# serialize an object
obj = AccountResource(authentication_key=...,...)
bbytes = obj.serialize()
# deserialize an object from bytes
obj = AccountResource.deserialize(bbytes)
```
### Json pretty print
For any canoser `Struct`, you can call the `to_json` method to get a formatted json string:
```python
# serialize an object
print(obj.to_json())
```
### Get field value from object
For all fields defined by the "\_fields", the value of this field of an object can be obtained via field_name. such as:
```python
obj.authentication_key
```
## Rust Type Alias
For simple type alias in rust, such as:
```rust
// in rust
pub type Round = u64;
```
We can define the alias like this:
```python
# in python
Round = Uint64
```
## Rust Tuple Struct
Struct like Address and ByteArray has no fields:
```rust
pub struct Address([u8; ADDRESS_LENGTH]);
pub struct ByteArray(Vec<u8>);
```
These struct called `tuple struct` in `Rust` programming language. Tuple struct is like `typedef` other than struct in `C` like programming languages.
You can just define them as a direct type, no struct. Just code like this:
```python
class TransactionArgument(RustEnum):
_enums = [
...
('Address', [Uint8, ADDRESS_LENGTH]),
...
]
```
Or you can define an `Address` class which inherit from `canoser.DelegateT` and has a `delegate_type` field with type `[Uint8, ADDRESS_LENGTH]`:
```python
class Address(DelegateT):
delegate_type = [Uint8, ADDRESS_LENGTH]
class TransactionArgument(RustEnum):
_enums = [
...
('Address', Address),
...
]
```
Do not instantiate a `canoser.DelegateT` type in assaignment, for example:
```python
transactionArgument.address = [...] #ok
transactionArgument.address = Address([...]) #error
```
## Notice
### Must define canoser struct by serialized fields and sequence, not the definition in the rust struct.
For example, the SignedTransaction in Libra is defined as following code:
```rust
pub struct SignedTransaction {
raw_txn: RawTransaction,
public_key: Ed25519PublicKey,
signature: Ed25519Signature,
transaction_length: usize,
}
```
But field `transaction_length` doesn't write to the output.
```rust
impl CanonicalSerialize for SignedTransaction {
fn serialize(&self, serializer: &mut impl CanonicalSerializer) -> Result<()> {
serializer
.encode_struct(&self.raw_txn)?
.encode_bytes(&self.public_key.to_bytes())?
.encode_bytes(&self.signature.to_bytes())?;
Ok(())
}
}
```
So we define SignedTransaction in canoser as following code:
```python
class SignedTransaction(canoser.Struct):
_fields = [
('raw_txn', RawTransaction),
('public_key', [Uint8, ED25519_PUBLIC_KEY_LENGTH]),
('signature', [Uint8, ED25519_SIGNATURE_LENGTH])
]
```
Here is another example. The definition sequence and serialize sequence is opposite in `WriteOp`
```rust
pub enum WriteOp {
Value(Vec<u8>),
Deletion,
}
enum WriteOpType {
Deletion = 0,
Value = 1,
}
impl CanonicalSerialize for WriteOp {
fn serialize(&self, serializer: &mut impl CanonicalSerializer) -> Result<()> {
match self {
WriteOp::Deletion => serializer.encode_u32(WriteOpType::Deletion as u32)?,
WriteOp::Value(value) => {
serializer.encode_u32(WriteOpType::Value as u32)?;
serializer.encode_vec(value)?
}
};
Ok(())
}
}
```
So, we define `WriteOp` as follow:
```python
class WriteOp(RustEnum):
_enums = [
('Deletion', None),
('Value', [Uint8])
]
```
## Related Projects
[MoveOnLibra OpenAPI: make writing libra wallet & move program easier](https://www.MoveOnLibra.com)
[A Ruby implementation of the LCS(Libra Canonical Serialization)](https://github.com/yuan-xy/canoser-ruby)
[A Python implementation of client APIs and command-line tools for the Libra network](https://github.com/yuan-xy/libra-client)
## License
The package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Raw data
{
"_id": null,
"home_page": "https://github.com/yuan-xy/canoser-python.git",
"name": "canoser",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "yuan xinyu",
"author_email": "yuan_xin_yu@hotmail.com",
"download_url": "https://files.pythonhosted.org/packages/77/30/48a2561ce369ef5bab964fb6d9ed193c73016c8cf0829df9693581e42026/canoser-0.8.2.tar.gz",
"platform": "",
"description": "A python implementation of the canonical serialization for the Libra network.\n\nCanonical serialization guarantees byte consistency when serializing an in-memory\ndata structure. It is useful for situations where two parties want to efficiently compare\ndata structures they independently maintain. It happens in consensus where\nindependent validators need to agree on the state they independently compute. A cryptographic\nhash of the serialized data structure is what ultimately gets compared. In order for\nthis to work, the serialization of the same data structures must be identical when computed\nby independent validators potentially running different implementations\nof the same spec in different languages.\n\n## Installation\n\nRequire python 3.6 or above installed.\n\n```sh\n$ python3 -m pip install canoser\n```\n\n\n## Usage\n\nFirst define a data structure with Canoser, that is, write a class that inherits from \"canoser.Struct\", and then define the fields owned by the structure through the \"\\_fields\" array. This structure naturally has the ability to canonical serialize and deserialize types. For example, the following AccountResource defines a data structure of the same name in the Libra code\uff1a\n```python\n #python code\uff0cdefine canoser data structure\nfrom canoser import Struct, Uint8, Uint64\nclass AccountResource(Struct):\n _fields = [\n ('authentication_key', [Uint8]),\n ('balance', Uint64),\n ('delegated_withdrawal_capability', bool),\n ('received_events', EventHandle),\n ('sent_events', EventHandle),\n ('sequence_number', Uint64)\n ]\n```\n\nHere is the code that defines this data structure and serialization in Libra code:\n```rust\n// rust code in Libra\n// define the data structure\npub struct AccountResource {\n balance: u64,\n sequence_number: u64,\n authentication_key: ByteArray,\n sent_events: EventHandle,\n received_events: EventHandle,\n delegated_withdrawal_capability: bool,\n}\n// serialization\nimpl CanonicalSerialize for AccountResource {\n fn serialize(&self, serializer: &mut impl CanonicalSerializer) -> Result<()> {\n serializer\n .encode_struct(&self.authentication_key)?\n .encode_u64(self.balance)?\n .encode_bool(self.delegated_withdrawal_capability)?\n .encode_struct(self.received_events)?\n .encode_struct(self.sent_events)?\n .encode_u64(self.sequence_number)?;\n Ok(())\n }\n}\n```\n~~In the rust language used by Libra, it is necessary to manually write code to serialize/deserialize the data structure, and the order of the fields in the data structure and the order of serialization are not necessarily the same.~~\n\nIn Canoser, after defining the data structure, you don't need to write code to implement serialization and deserialization. Note that the order of the data structures in Canoser is defined in the order in which they are serialized in Libra.\n\n### Supported field types\n\n| field type | optionl sub type | description |\n| ------ | ------ | ------ |\n| canoser.Uint8 | | Unsigned 8-bit integer |\n| canoser.Uint16 | | Unsigned 16-bit integer|\n| canoser.Uint32 | | Unsigned 32-bit integer |\n| canoser.Uint64 | | Unsigned 64-bit integer |\n| canoser.Uint128 | | Unsigned 128-bit integer |\n| canoser.Int8 | | Signed 8-bit integer |\n| canoser.Int16 | | Signed 16-bit integer|\n| canoser.Int32 | | Signed 32-bit integer |\n| canoser.Int64 | | Signed 64-bit integer |\n| canoser.Int128 | | Signed 128-bit integer |\n| bool | | Boolean |\n| str | | String |\n| bytes | | Binary String |\n| [] | supported | Array Type |\n| {} | supported | Map Type |\n| () | supported | Tuple Type |\n| canoser.Struct | | Another structure nested (cannot be recycled) |\n| RustEnum | | Enum type |\n| RustOptional | | Optional type |\n\n### About Array Type\nThe default data type (if not defined) in the array is Uint8. The following two definitions are equivalent:\n```python\n class Arr1(Struct):\n _fields = [(addr, [])]\n\n\n class Arr2(Struct):\n _fields = [(addr, [Uint8])]\n\n```\nArrays can also define lengths to represent fixed length data. For example, the address in Libra is 256 bits, which is 32 bytes, so it can be defined as follows:\n```python\n class Address(Struct):\n _fields = [(addr, [Uint8, 32])]\n```\nWhen the fixed length data is serialized, you can skip the length information written to the output. For example, following code will generate 32 bytes without writing the length of the addr during serialization.\n\n```python\n class Address(Struct):\n _fields = [(addr, [Uint8, 32, False])]\n```\n\n\n### About map type\nThe default data type (if not defined) in the map is an array of Uint8 in Libra, both of key and value.\nBut the python language dosn't support the array data type to be the key of a dict, so we change the key type from array of Uint8 to bytes in python, the type of value is unchanged.\nThe following two definitions are equivalent:\n```python\n class Map1(Struct):\n _fields = [(addr, {})]\n\n\n class Map2(Struct):\n _fields = [(addr, {bytes : [Uint8] })]\n\n```\n\n### About enum type\nIn python and C, enum is just enumerated constants. But in Libra(Rust), a enum has a type constant and a optional Value. A rust enumeration is typically represented as:\n\n```\nenum SomeDataType {\n type0(u32),\n type1(u64),\n type2\n}\n```\n\nTo define a enum with Canoser, first write a class that inherits from \"canoser.RustEnum\", and then define the types owned by the enum through the \"\\_enums\" array.\nFor example, the following TransactionArgument defines a data structure of the same name in the Libra code. The argument of a transaction can be one of the four types: Uint64 or Address or String or IntArray.\uff1a\n\n```python\nclass TransactionArgument(RustEnum):\n _enums = [\n ('U64', Uint64),\n ('Address', [Uint8, ADDRESS_LENGTH]),\n ('String', str),\n ('ByteArray', [Uint8])\n ]\n```\nYou can instantiate an enum obj and call its method and properties like this:\n\n```python\n arg2 = TransactionArgument('String', 'abc')\n assert arg2.index == 2\n assert arg2.value == 'abc'\n assert arg2.String == True\n assert arg2.U64 == False\n```\n\nEvery RustEnum object has an `index` property and a `value` property. After instantiated, the `index` can't be modified. You can only modify the `value` of an enum with correct data type.\n\nFor example, the following code is valid:\n\n```python\n arg2 = TransactionArgument('String', 'abc')\n arg2.value == 'Bcd'\n```\n\nFor example, the following code is invalid:\n```python\n arg2.index = 0 #raise an exception\n arg2.value = [3] #raise an exception\n```\n\nThe RustEnum can have a enum without value type, which represented by `None`.\n\n```python\nclass Enum1(RustEnum):\n _enums = [('opt1', [Uint8]), ('opt2', None)]\n\ne2 = Enum1('opt2', None)\n#or\ne2 = Enum1('opt2')\n```\n\nYou can also instantiate a RustEnum object by index and value.\n\n```python\ne1 = Enum1.new(0, [5])\n# which is equivalent to\ne1 = Enum1('opt1', [5])\n```\n\n### About optional type\nAn optional type in libra is a nullable data either exists in its full representation or does not. For example,\n\n```\noptional_data: Option(uint8); // Rust/Libra\nuint8 *optional_data; // C\n```\nIt has similar semantics meaning with the following enum type:\n```\nenum Option<uint8> {\n Some(uint8),\n None,\n}\n```\n\nTo define a optional with Canoser, first write a class that inherits from \"canoser.RustOptional\", and then define the types owned by RustOptional through the \"\\_type\" field. For example,\n\n```python\nclass OptionUInt(RustOptional):\n _type = Uint8\n\nnull = OptionUInt(None)\nobj = OptionUInt(8)\nassert obj.value == 8\n```\n\nHere's a complete example:\n\n```python\nclass OptionStr(RustOptional):\n _type = str\n\nclass OptionTest(Struct):\n _fields = [\n ('message', OptionStr)\n ]\n\n def __init__(self, msg=None):\n if msg is not None:\n self.message = OptionStr(msg)\n else:\n self.message = OptionStr(None)\n\ntest = OptionTest('test_str')\nassert test.message.value == 'test_str'\n```\n\n\nThe RustOptional type in canoser is similar to `typing.Optional` in python. Note that this is not the same concept as an optional argument, which is one that has a default.\n\n\n### Nested data structure\nThe following is a complex example with three data structures:\n```python\nclass Addr(Struct):\n _fields = [('addr', [Uint8, 32])]\n\n\nclass Bar(Struct):\n _fields = [\n ('a', Uint64),\n ('b', [Uint8]),\n ('c', Addr),\n ('d', Uint32),\n ]\n\nclass Foo(Struct):\n _fields = [\n ('a', Uint64),\n ('b', [Uint8]),\n ('c', Bar),\n ('d', bool),\n ('e', {}),\n ]\n```\nThis example refers to the test code from canonical serialization in libra.\n\n\n### Serialization and deserialization\nAfter defining canoser.Struct, you don't need to implement serialization and deserialization code yourself, you can directly call the default implementation of the base class. Take the AccountResource structure as an example:\n\n```python\n# serialize an object\nobj = AccountResource(authentication_key=...,...)\nbbytes = obj.serialize()\n\n# deserialize an object from bytes\nobj = AccountResource.deserialize(bbytes)\n```\n\n### Json pretty print\n\nFor any canoser `Struct`, you can call the `to_json` method to get a formatted json string:\n\n```python\n# serialize an object\nprint(obj.to_json())\n\n```\n\n### Get field value from object\n\nFor all fields defined by the \"\\_fields\", the value of this field of an object can be obtained via field_name. such as:\n```python\nobj.authentication_key\n```\n\n\n## Rust Type Alias\nFor simple type alias in rust, such as:\n```rust\n// in rust\npub type Round = u64;\n```\n\nWe can define the alias like this:\n\n```python\n# in python\nRound = Uint64\n```\n\n\n## Rust Tuple Struct\n\nStruct like Address and ByteArray has no fields:\n\n```rust\npub struct Address([u8; ADDRESS_LENGTH]);\npub struct ByteArray(Vec<u8>);\n```\n\nThese struct called `tuple struct` in `Rust` programming language. Tuple struct is like `typedef` other than struct in `C` like programming languages.\n\nYou can just define them as a direct type, no struct. Just code like this:\n```python\nclass TransactionArgument(RustEnum):\n _enums = [\n ...\n ('Address', [Uint8, ADDRESS_LENGTH]),\n ...\n ]\n```\n\nOr you can define an `Address` class which inherit from `canoser.DelegateT` and has a `delegate_type` field with type `[Uint8, ADDRESS_LENGTH]`:\n\n```python\nclass Address(DelegateT):\n delegate_type = [Uint8, ADDRESS_LENGTH]\n\n\nclass TransactionArgument(RustEnum):\n _enums = [\n ...\n ('Address', Address),\n ...\n ]\n```\n\nDo not instantiate a `canoser.DelegateT` type in assaignment, for example:\n\n```python\ntransactionArgument.address = [...] #ok\ntransactionArgument.address = Address([...]) #error\n```\n\n\n## Notice\n\n### Must define canoser struct by serialized fields and sequence, not the definition in the rust struct.\n\nFor example, the SignedTransaction in Libra is defined as following code:\n\n```rust\npub struct SignedTransaction {\n raw_txn: RawTransaction,\n public_key: Ed25519PublicKey,\n signature: Ed25519Signature,\n transaction_length: usize,\n}\n```\nBut field `transaction_length` doesn't write to the output.\n\n```rust\nimpl CanonicalSerialize for SignedTransaction {\n fn serialize(&self, serializer: &mut impl CanonicalSerializer) -> Result<()> {\n serializer\n .encode_struct(&self.raw_txn)?\n .encode_bytes(&self.public_key.to_bytes())?\n .encode_bytes(&self.signature.to_bytes())?;\n Ok(())\n }\n}\n```\n\nSo we define SignedTransaction in canoser as following code:\n```python\nclass SignedTransaction(canoser.Struct):\n _fields = [\n ('raw_txn', RawTransaction),\n ('public_key', [Uint8, ED25519_PUBLIC_KEY_LENGTH]),\n ('signature', [Uint8, ED25519_SIGNATURE_LENGTH])\n ]\n```\n\nHere is another example. The definition sequence and serialize sequence is opposite in `WriteOp`\n\n```rust\npub enum WriteOp {\n Value(Vec<u8>),\n Deletion,\n}\n\nenum WriteOpType {\n Deletion = 0,\n Value = 1,\n}\n\nimpl CanonicalSerialize for WriteOp {\n fn serialize(&self, serializer: &mut impl CanonicalSerializer) -> Result<()> {\n match self {\n WriteOp::Deletion => serializer.encode_u32(WriteOpType::Deletion as u32)?,\n WriteOp::Value(value) => {\n serializer.encode_u32(WriteOpType::Value as u32)?;\n serializer.encode_vec(value)?\n }\n };\n Ok(())\n }\n}\n```\n\nSo, we define `WriteOp` as follow:\n```python\nclass WriteOp(RustEnum):\n _enums = [\n ('Deletion', None),\n ('Value', [Uint8])\n ]\n\n```\n\n## Related Projects\n\n[MoveOnLibra OpenAPI: make writing libra wallet & move program easier](https://www.MoveOnLibra.com)\n\n[A Ruby implementation of the LCS(Libra Canonical Serialization)](https://github.com/yuan-xy/canoser-ruby)\n\n[A Python implementation of client APIs and command-line tools for the Libra network](https://github.com/yuan-xy/libra-client)\n\n\n\n## License\n\nThe package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "A python implementation of the LCS(Libra Canonical Serialization) for the Libra network.",
"version": "0.8.2",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "baa513b9a8f0b29776da6ac57ab060a3",
"sha256": "d450810e57fb53e5807eda481098d629474bff18643b9ece2a6e9150b7c36cce"
},
"downloads": -1,
"filename": "canoser-0.8.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "baa513b9a8f0b29776da6ac57ab060a3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 18170,
"upload_time": "2020-04-02T04:15:36",
"upload_time_iso_8601": "2020-04-02T04:15:36.377730Z",
"url": "https://files.pythonhosted.org/packages/5b/03/d6175731b6ee098dcd5989a0809345bd82dff1c2c8d1b3578bb37e5f034c/canoser-0.8.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "b609b63d86439ef4cd106f65a2ac8cef",
"sha256": "69a8f9d8d84aea353403642819df50cb7eb0282484cc5de67f34c85a8824151f"
},
"downloads": -1,
"filename": "canoser-0.8.2.tar.gz",
"has_sig": false,
"md5_digest": "b609b63d86439ef4cd106f65a2ac8cef",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 23464,
"upload_time": "2020-04-02T04:15:39",
"upload_time_iso_8601": "2020-04-02T04:15:39.501969Z",
"url": "https://files.pythonhosted.org/packages/77/30/48a2561ce369ef5bab964fb6d9ed193c73016c8cf0829df9693581e42026/canoser-0.8.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2020-04-02 04:15:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "yuan-xy",
"github_project": "canoser-python.git",
"lcname": "canoser"
}