github.com/crystal-community/msgpack-crystal
1.3.5 / published Nov 24, 2025 / repository
MessagePack implementation in Crystal msgpack.org[Crystal]
MessagePack
MessagePack implementation in Crystal.
Installation
Add this to your application's shard.yml:
dependencies:
msgpack:
github: crystal-community/msgpack-crystal
Usage
require "msgpack"
class Location
include MessagePack::Serializable
property lat : Float64
property lng : Float64
end
class House
include MessagePack::Serializable
property address : String
property location : Location?
end
house = House.from_msgpack({address: "Road12", location: {lat: 12.3, lng: 34.5}}.to_msgpack)
p house
# => <House:0x1b06de0 @address="Road12", @location=#<Location:0x1b06dc0 @lat=12.3, @lng=34.5>>
p house.to_msgpack
# => Bytes[130, 167, 97, 100, 100, 114, 101, 115, 115, 166, 82, 111, 97, 100, ...
house.address = "Something"
house = House.from_msgpack(house.to_msgpack)
p house
# => #<House:0x13f0d80 @address="Something", @location=#<Location:0x13f0d60 @lat=12.3, @lng=34.5>>
house = House.from_msgpack({"address" => "Crystal Road 1234"}.to_msgpack)
p house
# => <House:0x1b06d80 @address="Crystal Road 1234", @location=nil>
More Examples
Msgpack-RPC
implemented by simple_rpc shard
Copyright
Copyright 2015 Benoist Claassen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
API
- Array(T)
An
Arrayis an ordered, integer-indexed collection of objects of type T. - Enum
Enum is the base type of all enums.
- Hash(K, V)
A
Hashrepresents a collection of key-value mappings, similar to a dictionary. - MessagePack
- NamedTuple(**T)
A named tuple is a fixed-size, immutable, stack-allocated mapping of a fixed set of keys to values.
- Object
Objectis the base type of all Crystal objects. - Regex
A
Regexrepresents a regular expression, a pattern that describes the contents of strings. - Set(T)
Setimplements a collection of values with no duplicates. - Time
Timerepresents a date-time instant in incremental time observed in a specific time zone. - Tuple(*T)
A tuple is a fixed-size, immutable, stack-allocated sequence of values of possibly different types.