Conversation
新增以下 Java 兼容 API: 数组访问方法: - hasArray(): 检查是否有可访问数组 - array(): 返回底层字节数组 - arrayOffset(): 返回数组偏移量 直接缓冲区方法: - isDirect(): 判断是否为直接缓冲区 字节序方法: - ByteOrder 枚举:ORDER_BIG_ENDIAN / ORDER_LITTLE_ENDIAN - order(): 获取/设置字节序 - nativeOrder(): 获取主机字节序 - 自动字节交换支持(跨平台数据序列化) 比较和辅助方法: - compareTo(): 按字典序比较两个缓冲区 - hash(): 计算哈希值(用于 unordered 容器) - toString(): 字符串表示 单元测试: - 添加 27 个新测试用例,覆盖所有新接口 - 测试字节序转换的正确性 - 测试 compareTo、hash、toString 功能 实现细节: - 默认使用主机字节序 - 切换字节序后自动进行字节交换 - byteswap 模板函数支持任意类型
- 添加 Java 兼容接口章节 - 数组访问方法:hasArray, array, arrayOffset - 直接缓冲区方法:isDirect - 字节序方法:ByteOrder, order, nativeOrder - 比较和辅助方法:compareTo, hash, toString - 添加使用示例代码 - 更新注意事项中的字节序说明
- 在标题下方添加 Header-Only 说明 - 在特性列表中添加 Header-Only 标记 - 更新构建与测试章节,说明使用方法 - 添加单独的使用方法(Header-Only)章节
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
新增 Java ByteBuffer 兼容 API
本 PR 添加了与 Java ByteBuffer 兼容的接口,使 C++ 实现更接近 Java 原生 API。
新增接口
数组访问方法 (Java compatibility)
hasArray(): 检查是否有可访问数组array(): 返回底层字节数组arrayOffset(): 返回数组偏移量直接缓冲区方法
isDirect(): 判断是否为直接缓冲区字节序方法 (跨平台数据序列化)
ByteOrder枚举:ORDER_BIG_ENDIAN/ORDER_LITTLE_ENDIANorder(): 获取/设置字节序order(ByteOrder): 设置字节序nativeOrder(): 获取主机字节序比较和辅助方法
compareTo(const ByteBuffer&): 按字典序比较两个缓冲区hash(): 计算哈希值(用于 unordered_map 等容器)toString(): 字符串表示单元测试
添加了 27 个新测试用例,覆盖所有新接口:
hasArray,array,arrayOffset测试isDirect测试nativeOrder,order测试compareTo测试hash测试toString测试测试结果
新增 27 个测试用例,45 个断言。
使用示例
兼容性说明