kelindar/binary
Fork: 24 Star: 209 (更新于 2024-10-30 22:51:36)
license: MIT
Language: Go .
Generic and fast binary serializer for Go
最后发布版本: v1.0.19 ( 2024-02-25 21:42:02)
Generic and Fast Binary Serializer for Go
This repository contains a fast binary packer for Golang, this allows to encode/decode arbtitrary golang data structures of variable size. Documentation can be found on https://godoc.org/github.com/Kelindar/binary.
This package extends support to arbitrary, variable-sized values by prefixing these values with their varint-encoded size, recursively. This was originally inspired by Alec Thomas's binary package, but I've reworked the serialization format and improved the performance and size. Here's a few notable features/goals of this binary
package:
- Zero-allocation encoding. I'm hoping to make the encoding to be as fast as possible, simply writing binary to the
io.Writer
without unncessary allocations. - Support for
maps
,arrays
,slices
,structs
, primitive and nested types. - This is essentially a
json.Marshal
andjson.Unmarshal
drop-in replacement, I wanted this package to be simple to use and leverage the power ofreflect
package of golang. - The
ints
anduints
are encoded usingvarint
, making the payload small as possible. - Fast-paths encoding and decoding of
[]byte
, as I've designed this package to be used for inter-broker message encoding for emitter. - Support for custom
BinaryMarshaler
andBinaryUnmarshaler
for tighter packing control and built-in types such astime.Time
.
Usage
To serialize a message, simply Marshal
:
v := &message{
Name: "Roman",
Timestamp: 1242345235,
Payload: []byte("hi"),
Ssid: []uint32{1, 2, 3},
}
encoded, err := binary.Marshal(v)
To deserialize, Unmarshal
:
var v message
err := binary.Unmarshal(encoded, &v)
Disclaimer
This is not intended as a replacement for JSON or protobuf, this codec does not maintain any versioning or compatibility - and not intended to become one. The goal of this binary codec is to efficiently exchange binary data of known format between systems where you control both ends and both of them are written in Go.
最近版本更新:(数据更新于 2024-08-27 23:59:41)
2024-02-25 21:42:02 v1.0.19
2023-10-06 19:26:25 v1.0.18
2021-12-13 14:56:31 v1.0.17
2021-12-05 22:34:47 v1.0.16
2021-11-24 02:05:21 v1.0.15
2021-09-25 17:02:03 v1.0.14
2021-08-03 20:23:41 v1.0.13
2021-08-01 22:50:31 v1.0.12
2021-08-01 22:30:10 v1.0.11
2021-06-17 15:44:33 v1.0.10
主题(topics):
binary, codec, decoding, encoding, generic, golang, serialization
kelindar/binary同语言 Go最近更新仓库
2024-11-05 08:55:31 XTLS/Xray-core
2024-11-05 00:03:47 SagerNet/sing-box
2024-11-04 20:34:19 Permify/permify
2024-11-04 15:07:27 containerd/containerd
2024-11-03 20:10:56 flipped-aurora/gin-vue-admin
2024-11-03 00:46:25 dolthub/dolt