# avro **Repository Path**: openharmony-sig/avro ## Basic Information - **Project Name**: avro - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 10 - **Created**: 2022-04-16 - **Last Updated**: 2025-05-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # avro ## Overview This project is modified based on the open-source software [Apache Avro](https://github.com/apache/avro) to adapt to OpenHarmony. It supports various data structures and converts them into binary data formats that are easy to store or transmit. It can also serve as a container to store persistent data. ## Effect: ![apache avro](./screenshot/avro.gif) ## How to Install ```` ohpm install @ohos/avro-js ```` For details, see [Installing an OpenHarmony HAR](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.en.md). ## How to Use ### Sample Code 1. Introduce avro to the page. ``` import avro from '@ohos/avro-js' ``` 2. Use avro to implement data serialization. ``` let mapType: ESObject = avro.parse({ type: 'map', values: 'long' }) let petMap: petMapType = { key1: 12343, key2: 3445 }; let bufMap: ESObject = mapType.toBuffer(petMap); // Buffer containing 'Hi''s Avro encoding. let mapSrc: ESObject = mapType.fromBuffer(bufMap); // === 'Hi' let bufferStr = ""; for (let i = 0; i < bufMap.length; i++) { bufferStr = bufferStr + bufMap[i]; } this.mapTestResult = "MapType:{original data: " + JSON.stringify(petMap) +", serialization: " + bufferStr +", Restored data: " + JSON.stringify(mapSrc) + "};"; console.info("----MapType--{original_data:" + JSON.stringify(petMap) + ",serialization: " + bufferStr + ",restore_data: " + JSON.stringify(mapSrc) + "}"); ``` ## Available APIs 1. `avro.parse(schema, opts)`: Parses the schema and returns the corresponding instance. 2. `type.toBuffer(val)`: Encodes the given value into a binary buffer. 3. `type.fromBuffer(buf, [resolver,] [noCheck])`: Creates a new instance from the binary buffer. 4. `type.decode(buf, [pos,] [resolver])`: Decodes the data in the binary buffer to the specified position and parser. 5. `type.encode(val, buf, [pos])`: Encodes the given value into a binary buffer. 6. `type.fromString(str)`: Creates an instance from a string. 7. `type.toString([val])`: Converts the given value to a string. 8. `type.isValid(val, [opts])`: Checks whether the given value is valid. 9. `type.clone(val, [opts])`: Creates a deep copy of a given value. 10. `type.compare(val1, val2)`: Compares two values. 11. `type.compareBuffers(buf1, buf2)`: Compares the sizes of two binary buffers. 12. `type.random()`: Generates a new random value. 13. `type.getName([noRef])`: Obtains the type name. 14. `type.getSchema([noDeref])`: Obtains the type schema. 15. `type.getItemsType()`: Obtains the array or mapping type. 16. `type.getAliases()`: Obtains the type alias. 17. `type.getSize()`: Obtains the type size. 18. `type.getValuesType()`: Obtains values of the enum or fixed type. ## Constraints avro has been verified in the following version: - DevEco Studio: 4.1 Canary (4.1.3.317), OpenHarmony SDK: API11 (4.1.0.36) ## Directory Structure ```` |---- avro | |---- entry # Sample code | |---- library # avro library | |---- README_EN.md # Readme ```` ## How to Contribute If you find any problem when using avro, submit an [Issue](https://gitee.com/openharmony-sig/avro/issues) or a [PR](https://gitee.com/openharmony-sig/avro/pulls). ## License This project is licensed under [Apache License 2.0](https://gitee.com/openharmony-sig/avro/blob/master/LICENSE).