You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* indexed by class name instead of the class itself
* serializer 1.0
* Implemented deserializer
* Fixed indentation
* Added schema validation
* minor improvements
* added more tests
* added more tests
* added more tests
* updated readme
* minor fix to examples
* bump in version
* minor update to README.md
* minor update to README.md
* trigger actions
* Removed unnecesary packages + fixed lint
* simplified buffer
* added base encode/decode
* implemented enums and removed deserializing of classes
* better organized testing
* exported schema
* Added forgotten schemas to schema type
* allowing numbers in BN
* schema now leads serialization order
* bump version
* feat: allow strings in BN
* feat: more tests & checkSchema flag
* fix: made compatible to ES5
* updated readme
* feat: building cjs & esm
* feat: cjs & esm working versions
* removed BN.js & bs58
* simplified tests
* small change in bigint method
* added compatibility with BN
-`serialize(schema: Schema, obj: any): Uint8Array` - serializes an object `obj` according to the schema `schema`.
43
+
-`deserialize(schema: Schema, buffer: Uint8Array, class?: Class): any` - deserializes an object according to the schema `schema` from the buffer `buffer`. If the optional parameter `class` is present, the deserialized object will be an of `class`.
44
+
45
+
## Schemas
46
+
Schemas are used to describe the structure of the data being serialized or deserialized. They are used to
47
+
validate the data and to determine the order of the fields in the serialized data.
48
+
49
+
> NOTE: You can find examples of valid in the [test](./borsh-ts/test/utils.test.js) folder.
50
+
51
+
### Basic Types
52
+
Basic types are described by a string. The following types are supported:
53
+
-`u8`, `u16`, `u32`, `u64`, `u128` - unsigned integers of 8, 16, 32, 64, and 128 bits respectively.
54
+
-`i8`, `i16`, `i32`, `i64`, `i128` - signed integers of 8, 16, 32, 64, and 128 bits respectively.
55
+
-`f32`, `f64` - IEEE 754 floating point numbers of 32 and 64 bits respectively.
56
+
-`bool` - boolean value.
57
+
-`string` - UTF-8 string.
58
+
59
+
### Arrays, Options, Maps, Sets, Enums, and Structs
60
+
More complex objects are described by a JSON object. The following types are supported:
61
+
-`{ array: { type: Schema, len?: number } }` - an array of objects of the same type. The type of the array elements is described by the `type` field. If the field `len` is present, the array is fixed-size and the length of the array is `len`. Otherwise, the array is dynamic-sized and the length of the array is serialized before the elements.
62
+
-`{ option: Schema }` - an optional object. The type of the object is described by the `type` field.
63
+
-`{ map: { key: Schema, value: Schema }}` - a map. The type of the keys and values are described by the `key` and `value` fields respectively.
64
+
-`{ set: Schema }` - a set. The type of the elements is described by the `type` field.
65
+
-`{ enum: [{ className1: { struct: {...} } }, { className2: { struct: {...} } }, ... ] }` - an enum. The variants of the enum are described by the `className1`, `className2`, etc. fields. The variants are structs.
66
+
-`{ struct: { field1: Schema1, field2: Schema2, ... } }` - a struct. The fields of the struct are described by the `field1`, `field2`, etc. fields.
0 commit comments