Giter VIP home page Giter VIP logo

buffer's Introduction

buffer

Simple bytes reader in pure V, adapted from go version of bytes.Reader

Installation

$v install https://github.com/blackshirt/buffer

and then import it in your modules.

Usage

// import module
import blackshirt.buffer

// create new reader with given arrays of bytes as an input.
// data := []u8
mut reader := buffer.new_reader(data)
// example read one byte 
byte := r.read_byte()!
// read two byte
twobyte := r.read_u16()!
// do with a byte or two byte

and then you can call desired methods.

Contents

new_reader

fn new_reader(b []u8) &Reader

create new Reader with big endianess set to true, for more other option, see new_reader_with_endianess function.

[Return to contents]

new_reader_with_endianess

fn new_reader_with_endianess(b []u8, endian bool) &Reader

new_reader_with_endianess create new reader.

[Return to contents]

Reader

reset

fn (mut r Reader) reset(b []u8)

resets the Reader to be reading from b

[Return to contents]

remainder

fn (r &Reader) remainder() int

remainder tells the length of unread portion of buffer.

[Return to contents]

cap

fn (r &Reader) cap() i64

cap return capacity or original size of the buffer.

[Return to contents]

sub_reader

fn (mut r Reader) sub_reader(start i64, amount i64) !&Reader

sub_reader create sub Reader from defined current reader.

[Return to contents]

read_u8

fn (mut r Reader) read_u8() !u8

read_u8 read one byte and updates current index

[Return to contents]

read_byte

fn (mut r Reader) read_byte() !u8

read_byte is an alias for read_u8

[Return to contents]

peek_u8

fn (mut r Reader) peek_u8() !u8

peek_u8 peek one byte without udpates current index

[Return to contents]

read

fn (mut r Reader) read(mut b []u8) !int

implements io.Reader read b.len bytes from reader, and updates current index

[Return to contents]

peek

fn (mut r Reader) peek(mut b []u8) !int

read b.len bytes from reader, without updates current index

[Return to contents]

read_sized

fn (mut r Reader) read_sized(size int) !([]u8, int)

read with size

[Return to contents]

peek_sized

fn (mut r Reader) peek_sized(size int) !([]u8, int)

peek_sized peek with size

[Return to contents]

read_at_least

fn (mut r Reader) read_at_least(amount int) ![]u8

read in amount size from current offset

[Return to contents]

skip

fn (mut r Reader) skip(amount int)

skip amount of bytes and updates index, its similar to peek but only update the index.

[Return to contents]

read_to_end

fn (mut r Reader) read_to_end() ![]u8

read from current index to the end of the buffer update the idx to the last

[Return to contents]

read_u16

fn (mut r Reader) read_u16() !u16

read u16 size (two byte) from reader

[Return to contents]

peek_u16

fn (mut r Reader) peek_u16() !u16

peek u16 size (two bytes) from reader.

[Return to contents]

read_u24

fn (mut r Reader) read_u24() !int

read_u24 read 3 bytes from reader, and return integer and updates index

[Return to contents]

peek_u24

fn (mut r Reader) peek_u24() !int

peek_u24 peek 3 bytes from reader without updates index.

[Return to contents]

read_u32

fn (mut r Reader) read_u32() !u32

read_u32 read u32size bytes data from reader and updatea index

[Return to contents]

peek_u32

fn (mut r Reader) peek_u32() !u32

peek_u32 peek u32size bytes fron reader without updates index

[Return to contents]

read_u64

fn (mut r Reader) read_u64() !u64

read_u64 read u64size (8) bytes from reader and updates index

[Return to contents]

peek_u64

fn (mut r Reader) peek_u64() !u64

peek_u64 peek u64size bytes from reader withhout updates index.

[Return to contents]

remaining

fn (r &Reader) remaining() ![]u8

remaining bytes without update the index

[Return to contents]

buffer's People

Contributors

blackshirt avatar

Stargazers

ylluminate avatar  avatar

Watchers

 avatar  avatar

buffer's Issues

how to read like golang binary.read() with struct config?

on GO work like:

struct Config {
    abc int
    def  int
    ijk int
}

config := Config{} // fn (config Config) sss() {}
binary.read(read_file, binary.LittleEndian, config)

using your module how work like go, and on vlang?
Would be like this or not:

struct Config {
    abc int
    def  int
    ijk int
}

file := buffer.new_reader(...)
config := Config{} // fn (config Config) sss() {}
buffer.read(file, config, true)

i need go like read fn, Please show me example. thanks.

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.