package cstruct

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Big-endian Byte Order

The following operations assume a big-endian byte ordering of the cstruct. If the machine-native byte ordering differs, then the get operations will reorder the bytes so that they are in machine-native byte order before returning the result, and the set operations will reorder the bytes so that they are written out in the appropriate order.

Network byte order is big-endian, so you may need these operations when dealing with raw frames, for example, in a userland networking stack.

val get_uint16 : 'a rd t -> int -> uint16

get_uint16 t off returns the two bytes in t starting at offset off, interpreted as an uint16. t needs at least read capability rd.

  • raises Invalid_argument

    if offset off exceeds length t - 2.

val get_uint32 : 'a rd t -> int -> uint32

get_uint32 t off returns the four bytes in t starting at offset off. t needs at least read capability rd.

  • raises Invalid_argument

    if offset off exceeds length t - 4.

val get_uint64 : 'a rd t -> int -> uint64

get_uint64 t off returns the eight bytes in t starting at offset off. t needs at least read capability rd.

  • raises Invalid_argument

    if offset off exceeds length t - 8.

val set_uint16 : 'a wr t -> int -> uint16 -> unit

set_uint16 t off v sets the two bytes in t starting at offset off to the value v. t needs at least write capability wr.

  • raises Invalid_argument

    if offset off exceeds length t - 2.

val set_uint32 : 'a wr t -> int -> uint32 -> unit

set_uint32 t off v sets the four bytes in t starting at offset off to the value v. t needs at least write capability wr.

  • raises Invalid_argument

    if offset off exceeds length t - 4.

val set_uint64 : 'a wr t -> int -> uint64 -> unit

set_uint64 t off v sets the eight bytes in t starting at offset off to the value v. t needs at least write capability wr.

  • raises Invalid_argument

    if offset off exceeds length t - 8.