diff options
| author | tanaka takashi <isazaka@gmail.com> | 2026-06-29 21:43:54 +0900 |
|---|---|---|
| committer | tanaka takashi <isazaka@gmail.com> | 2026-06-30 01:23:51 +0900 |
| commit | 4bc721c3bf7589b519c5730d093f704ce56e3f09 (patch) | |
| tree | 38da055ab15fd70f5c92584560ea73486e5ddce0 /src/storage/codec.c | |
| parent | 4c6a831aa2a57e2bcc20aa3fc2f1b7172f5be285 (diff) | |
refactor: MCP層をmcpc APIベースに刷新
- 独自JSON-RPC処理をmcpcへ置き換え
- 各MCPツールを個別ソースへ分離
- 共通コンテキストと登録処理を整理
- mcpc互換修正と統合テストを更新
Diffstat (limited to 'src/storage/codec.c')
| -rw-r--r-- | src/storage/codec.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/storage/codec.c b/src/storage/codec.c new file mode 100644 index 0000000..af061ce --- /dev/null +++ b/src/storage/codec.c @@ -0,0 +1,76 @@ +#include "storage/codec.h" + +void +tiny_codec_put_u32(unsigned char *output, uint32_t value) +{ + if (output == NULL) + { + return; + } + output[0] = (unsigned char)value; + output[1] = (unsigned char)(value >> 8); + output[2] = (unsigned char)(value >> 16); + output[3] = (unsigned char)(value >> 24); +} + +void +tiny_codec_put_u64(unsigned char *output, uint64_t value) +{ + unsigned index; + if (output == NULL) + { + return; + } + for (index = 0; index < 8; ++index) + { + output[index] = (unsigned char)(value >> (index * 8)); + } +} + +uint32_t +tiny_codec_get_u32(const unsigned char *input) +{ + if (input == NULL) + { + return 0; + } + return (uint32_t)input[0] | ((uint32_t)input[1] << 8) | ((uint32_t)input[2] << 16) + | ((uint32_t)input[3] << 24); +} + +uint64_t +tiny_codec_get_u64(const unsigned char *input) +{ + uint64_t value = 0; + int index; + if (input == NULL) + { + return 0; + } + for (index = 7; index >= 0; --index) + { + value = (value << 8) | input[index]; + } + return value; +} + +uint32_t +tiny_codec_crc32(const unsigned char *data, size_t length) +{ + uint32_t crc = 0xffffffffU; + size_t index; + if (data == NULL && length != 0) + { + return 0; + } + for (index = 0; index < length; ++index) + { + unsigned bit; + crc ^= data[index]; + for (bit = 0; bit < 8; ++bit) + { + crc = (crc >> 1) ^ (0xedb88320U & (uint32_t)-(int32_t)(crc & 1)); + } + } + return ~crc; +} |
