cbor-gen-for

command module
v0.0.0-...-5d17c9d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2023 License: Apache-2.0, MIT Imports: 11 Imported by: 0

README

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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL