Giter Club home page Giter Club logo

odin-msgpack's Introduction

odin-msgpack

Implementation of msgpack in odin Suport for Writer & Reader & Un/Marshal & Extensions

Tests

Basic test code can be found in test.odin, prints out write / read results mostly useful to check un/marshal support

Basic Example

package main

import "core:fmt"
import msgpack "shared:odin-msgpack"

// or_return checks the call for a possible error, leaves early on error
// reader would have to read these in the same order
write :: proc(ctx: ^msgpack.Write_Context) -> (err: msgpack.Write_Error) {
	msgpack.write_int8(ctx, 10) or_return
	msgpack.write_nil(ctx) or_return
	msgpack.write_string(ctx, "test") or_return
	return
}

main :: proc() {
	ctx := msgpack.write_context_init(1024)
	defer msgpack.write_context_destroy(ctx)
    
	err := write(&ctx)
	if err != .None {
		fmt.panic("error: %v", err)
	}
    
	fmt.println(msgpack.write_context_result(ctx))
}

Magic

package main

import "core:fmt"
import msgpack "shared:odin-msgpack"

main :: proc() {
	Struct_A :: struct {
		a: int,
		b: bool,
	}

	// write write_data automatically into msgpack data
	write_data := Struct_A { a = 1, b = true }
	bytes, write_err := msgpack.marshal(write_data, 1024)
	defer delete(bytes)
	assert(write_err == .None)

	// read data automatically back into read_data
	read_data: Struct_A
	read_err := msgpack.unmarshal(read_data, bytes)
	assert(read_err == .None)

	// both are equal
	assert(write_data == read_data)
}

Warning

msgpack is dynamic, meaning you could have arrays with different types or maps with different key / value pairs odin does not support this, so whenever you expect dynamic results in arrays / maps you have to explicitly us the reader / writer

Exception

marshal & unmarshal do read / write dynamic msgpack data, i.e. a struct will be written to msgpack as a string + any odin data type If you encounter issues with these, please write issues / pull requests

odin-msgpack's People

Contributors

skytrias 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.