MyGit

kelindar/binary

Fork: 24 Star: 211 (更新于 2024-12-17 12:49:26)

license: MIT

Language: Go .

Generic and fast binary serializer for Go

最后发布版本: v1.0.19 ( 2024-02-25 21:42:02)

官方网址 GitHub网址

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 and json.Unmarshal drop-in replacement, I wanted this package to be simple to use and leverage the power of reflect package of golang.
  • The ints and uints are encoded using varint, 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 and BinaryUnmarshaler for tighter packing control and built-in types such as time.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-12-22 07:52:58 navidrome/navidrome

2024-12-21 20:15:12 SagerNet/sing-box

2024-12-21 03:25:54 SpecterOps/BloodHound

2024-12-19 23:11:24 shadow1ng/fscan

2024-12-19 21:50:56 minio/minio

2024-12-19 10:04:39 istio/istio