Skip to content

Latest commit

 

History

History
90 lines (61 loc) · 2.7 KB

README.md

File metadata and controls

90 lines (61 loc) · 2.7 KB

Shimmering Bee: Byte Codec

license standard-readme compliant Actions Status

Implementation of a byte codec to Marshal/Unmarshal structs to []byte, compatible with Zigbee types, written in Go.

Table of Contents

Background

bytecodec is a library to marshal and unmarshal Go structs to a []byte, for transmission on the wire. Compatible with Zigbee types, such as 24 bit integers.

Install

Add an import and most IDEs will go get automatically, if it doesn't go build will fetch.

import "github.com/shimmeringbee/bytecodec"

Usage

This libraries API is unstable and should not yet be relied upon.

Marshalling

Marshalling assumes integers should be expressed as little endian, unless overridden.

Currently supports:

  • uint8, uint16, uint32, uint64
  • struct
  • array/slice
  • string (null terminated and length prefixed)
type StructToMarshal struct {
    ByteField              byte
    ArrayOfUint16BigEndian []uint16 `bcendian:"big"`
    Uint16LittleEndian     uint16
}

data := &StructToMarshal{
    ByteField:              0x55,
    ArrayOfUint16BigEndian: []uint16{0x8001, 0x1234},
    Uint16LittleEndian:     0x2233,
}

bytes, err := bytecodec.Marshal(data)

if err != nil {
    // Handle Error
}

// bytes = []byte{0x55,0x80,0x01,0x12,0x34,0x33,0x22}

Maintainers

@pwood

Contributing

Feel free to dive in! Open an issue or submit PRs.

All Shimmering Bee projects follow the Contributor Covenant Code of Conduct.

License

Copyright 2019-2020 Shimmering Bee Contributors

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.