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

no-std memcached-network-types

Provides types for memcached protocol entities used for sending requests and responses over the network

5 releases

0.1.4 Jul 18, 2024
0.1.3 Jul 14, 2024
0.1.2 Jul 14, 2024
0.1.1 Jul 14, 2024
0.1.0 Jul 13, 2024

#1527 in Network programming

Download history 11/week @ 2024-09-10 2/week @ 2024-09-17 14/week @ 2024-09-24 1/week @ 2024-10-01

180 downloads per month

MIT license

17KB
334 lines

memcached-network-types

Provides types for memcached protocol entities used for sending requests and responses over the network.

Usage

memcached-network-types is a nostd library crate. You may include it in your Cargo.toml as follows:

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

Refer to latest git API Documentation for more details.

Example

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);

License

This repository is licensed under the MIT License. See LICENSE for more details.

Dependencies

~0.9–1.5MB
~26K SLoC