Skip to content

hannahhoward/cbor-gen-for

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cbor-gen-for

Automatically add CBOR serialization/deserialization with go generate and cbor-gen

Usage

  • install with go mod

  • in a file with types you want to generate cbor for, add a go-generate comment:

objects.go

package objects

//go:generate cbor-gen-for Car House

type Car struct {
  WheelType string
  HorsePower uint64
}

type House struct {
  Stories uint64
  Color string
}
  • run go generate ./... to make cbor serialization code for your whole project

This will make cbor serialization files of the name original-file-name_cbor_gen.go in the original location

Note that the project must be compilable first to do this, so if you get errors, make sure go build ./... works first.

Caveat

Since this is a generator that doesn't go into the actual code for your project, to retain during go mod tidy you should add a file at the root with a seperate build target, a.l.a. https://github.com/go-modules-by-example/index/tree/master/010_tools

// +build tools

package tools

import (
	_ "github.com/hannahhoward/cbor-gen-for"
)

License

This repository is dual-licensed under Apache 2.0 and MIT terms.

Copyright 2019. Protocol Labs, Inc.

About

A cmd line executable for cbor-gen

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages