Code Monkey home page Code Monkey logo

cursor's Introduction

Build Status Coverage Status

cursor

A simple iterator for packing/unpacking primitive c types to/from a provided buffer.

Example

    /* A buffer to store packed data */
    uint8_t buf[6];

    /* Construct a new writer cursor with the buffer we just defined */
    struct cursor_wtr wtr = cursor_wtr_new(buf, sizeof(buf));

    uint16_t written_u16 = 0x0123;
    uint32_t written_u32 = 0x456789AB;

    /* Write written_u16 to buf little-endian */
    cursor_pack_le_u16(&wtr, written_u16);

    /* Write written_u32 to buf big-endian */
    cursor_pack_be_u32(&wtr, written_u32);

    /* Construct a reader cursor */
    struct cursor_rdr rdr = cursor_rdr_new(buf, sizeof(buf));

    uint16_t read_u16 = 0;
    uint32_t read_u32 = 0;

    /* Read a packed little-endian uint16_t out of buf */
    cursor_unpack_le_u16(&rdr, &read_u16);

    /* Read a packed big-endian uint32_t out of buf */
    cursor_unpack_be_u32(&rdr, &read_u32);

    assert(read_u16 == written_u16);
    assert(read_u32 == written_u32);

See the full example.

cursor's People

Contributors

jaykickliter avatar lthiery avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lthiery zabrane

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.