Skip to content

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

License

Notifications You must be signed in to change notification settings

blackshirt/buffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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]

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages