GithubHelp home page GithubHelp logo

mixed_fields's Introduction

MixedFields Binary Format

MixedFields is a lightweight, variable field length binary format. It's currently in pre-alpha.

Writing binary data to a file:

>>> import mixed_fields
>>> mf = mixed_fields.MixedFields(r'test.mixd')
>>> mf.write_item(b'Spam')
>>> mf.write_item(b'And eggs!')
>>> mf.write_item(b'We require...a shrubbery!')
>>> mf.write_item(b'\x01\x02\x03\x04')
>>> import pickle
>>> mf.write_item(pickle.dumps({'keyA': 'valueA'}))
>>> mf.close()

Lazy read items from the same MixedFields file:

>>> import mixed_fields
>>> mf = mixed_fields.MixedFields(r'test.mixd')
>>> mf.read_item()
b'Spam'
>>> mf.read_item()
b'And eggs!'
>>> mf.read_item()
b'We require...a shrubbery!'
>>> mf.read_item()
b'\x01\x02\x03\x04'
>>> val = pickle.loads(mf.read_item()); val
{'keyA': 'valueA'}
>>> mf.read_item()  # Note, empty bytes means EOF has been reached
b''

The file format consists entirely of tagged fields, where each field is <tag> + <payload> + <endbyte>. Tags are <start_byte> + <4 letter tag name>, for example the header tag is b'\x1cMixd'.

Variable size fields have a length subfield just before the payload, which itself is variable size (the leading bit of each byte is 1 when there's a continuation byte, and 0 when the last byte of the size field has been reached, so 7 bit lengths only need 1 size byte starting with 0).

Every file has a header field, metadata field (variable length), optionally some data fields, and an end-of-file field.

Currently, only data fields can be added by users. User metadata fields and fixed length fields are planned for the future, as well as custom user fields.

mixed_fields's People

Contributors

ericsnekbytes avatar

Watchers

 avatar

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.