#memcached #networking #packet-parsing #no-std

无 std memcached-network-types

提供用于在网络中发送请求和响应的 memcached 协议实体的类型。

5 个版本

0.1.4 2024 年 7 月 18 日
0.1.3 2024 年 7 月 14 日
0.1.2 2024 年 7 月 14 日
0.1.1 2024 年 7 月 14 日
0.1.0 2024 年 7 月 13 日

网络编程 中排名第 542

Download history 186/week @ 2024-07-09 127/week @ 2024-07-16 9/week @ 2024-07-30

每月下载量 322

MIT 许可证

17KB
334

memcached-network-types

提供用于在网络中发送请求和响应的 memcached 协议实体的类型。

用法

memcached-network-types 是一个 nostd 库 Crates。您可以在您的 Cargo.toml 中如下添加它

[dependencies]
memcached-network-types = "0.1.4"

有关详细信息,请参阅最新的 Git API 文档

示例

use memcached_network_types::binary::*;

let req_get_packet_header = ReqPacketHeader {
    magic_byte: ReqMagicByte::ReqPacket,
    opcode: Opcode::Get,
    key_length: 0.into(),
    extras_length: 0,
    data_type: DataType::RawBytes,
    vbucket: 0.into(),
    total_body_length: 0.into(),
    opaque: [0; 4],
    cas: [0; 8],
};

let bytes = req_get_packet_header.as_bytes();

let req_get_packet_header_parsed = ReqPacketHeader::ref_from(bytes).unwrap();

assert!(&req_get_packet_header == req_get_packet_header_parsed);

let req_get_packet_header_parsed =
    ReqPacketHeader::ref_req_packet_header_with_possible_opcode_from(bytes, &[Opcode::Get])
        .unwrap();

assert!(&req_get_packet_header == req_get_packet_header_parsed);

const GET_OPCODE: u8 = Opcode::Get as u8;

let req_get_packet_header_parsed = unsafe {
    ReqPacketHeader::ref_req_packet_header_with_opcode_from::<GET_OPCODE>(bytes).unwrap()
};

assert!(&req_get_packet_header == req_get_packet_header_parsed);

let req_get_packet_header_parsed =
    ReqPacketHeader::ref_req_packet_header_with_get_opcode_from(bytes).unwrap();

assert!(&req_get_packet_header == req_get_packet_header_parsed);

许可证

本存储库采用 MIT 许可证授权。有关详细信息,请参阅 LICENSE

依赖项

~0.8–1.4MB
~26K SLoC