GithubHelp home page GithubHelp logo

nvm-log's Introduction

nvm-log

State

The logger maintains just one piece of state: the position (specifically, the address of the first byte) where the next log can be written.

Writing a message

Our messages do not cross page boundaries. This is convenient for erasing (erasing a page will never erase half of a message) and works better with the ring-buffer structure of the memory.

The message is first seralized to a temporary buffer, to determine its length. Then either

  • The message fits in the remaining space of the current page. The message is written to the page, starting at the current position
  • The message does not fit in the current page. In this case the current block is sealed with zero bytes. NOTE: there can be many consequtive zero bytes, even zero words, when the message type is big. The message is then written to the next page, which may loop back around to the first page if the last page is full.

A message starts with a header word (which indicates whether the message is active or not). Then come the serialized bytes, and then we pad to the next word boundary with zero bytes.

Finding the current position

After a reboot, the current log position is lost. We can find the log position by finding a non-sealed page (so the final word is 0xFFFFFFFF), then searching in that page for the last zero byte. The start of the next word is the current position.

If all blocks are sealed, we default to using the first byte of the first page as the current position. The first page is cleared in this case.

Iterating over messages

Starting from the current position, we scan through the pages to find the next page that has any content, then parse the messages, starting with either an active or inactive header. For those with an active header, the message bytes are decoded, and the header is set to inactive (this works because the active -> inactive transformation only turns 1 bits into 0 bits). The decoded message is yielded.

nvm-log's People

Contributors

folkertdev avatar diondokter avatar hdoordt avatar

Stargazers

Jeff Carpenter avatar Paolo Barbolini avatar

Watchers

abudaan avatar James Cloos avatar Marlon avatar Erik Jonkers avatar  avatar  avatar

nvm-log's Issues

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.