memcached-network-types

Crates.iomemcached-network-types
lib.rsmemcached-network-types
version0.1.4
sourcesrc
created_at2024-07-13 07:40:48.108774
updated_at2024-07-18 16:09:19.255344
descriptionProvides types for memcached protocol entities used for sending requests and responses over the network.
homepage
repositoryhttps://github.com/arindas/memcached-network-types
max_upload_size
id1302113
size18,675
Arindam Das (arindas)

documentation

README

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.

Commit count: 0

cargo fmt