package

github.com/vypxl/serialize.cr

master / published May 9, 2020 / repository

serialize.cr

This project will probably never get finished. If you want to use it, you may ask me, but I probably won't continue working on this.

Provides easy serialization of arbitrary complex objects in JSON/Yaml and Messagepack. This uses the msgpack-crystal library by crystal-community.

What is working

  • Full [de-]serialization of instances containing one of
    • Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64
    • Bool
    • Float
    • Nil
    • String
    • Arrays / Hashes / Tuples / Slices of these into / from YAML and MessagePack

Missing

  • JSON support

  • NamedTuple (Not possible because I can not get the types of the NT)

  • Time[::Format]

  • Symbol

Installation

Add this to your application's shard.yml:

dependencies:
  serialize.cr:
    github: vypxl/serialize.cr

Usage

require "serialize.cr"

yaml = obj.ser_yaml # serialize to YAML
mp = obj.ser_msgpack # serialize to MessagePack

new_from_yaml = Obj.deser_yaml yaml # deserialize from YAML
new_from_msgpack = Obj.deser_msgpack mp # deserialize from MessagePack

Contributors

  • vypxl - creator, maintainer

API

  • Array(T)

    An Array is an ordered, integer-indexed collection of objects of type T.

  • Bool

    Bool has only two possible values: true and false.

  • Enum

    Enum is the base type of all enums.

  • Float

    Float is the base type of all floating point numbers.

  • Hash(K, V)

    A Hash represents a collection of key-value mappings, similar to a dictionary.

  • Int16
  • Int32
  • Int64
  • Int8
  • Nil

    The Nil type has only one possible value: nil.

  • Serializable
  • Slice(T)

    A Slice is a Pointer with an associated size.

  • String

    A String represents an immutable sequence of UTF-8 characters.

  • Tuple(*T)

    A tuple is a fixed-size, immutable, stack-allocated sequence of values of possibly different types.

  • UInt16
  • UInt32
  • UInt64
  • UInt8