Skip to content

Instantly share code, notes, and snippets.

@johanbrandhorst
Last active October 4, 2016 11:55
Show Gist options
  • Save johanbrandhorst/715a061bb4610a39c35396800c2a3121 to your computer and use it in GitHub Desktop.
Save johanbrandhorst/715a061bb4610a39c35396800c2a3121 to your computer and use it in GitHub Desktop.
Generate invalid timestamp code
# Install protoc3. Left as exercise to reader
# Install protoc-gen-gogo and friends
go get github.com/gogo/protobuf/proto
go get github.com/gogo/protobuf/jsonpb
go get github.com/gogo/protobuf/protoc-gen-gogo
go get github.com/gogo/protobuf/gogoproto
# Generate file
protoc my.proto --gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types:./ -I./ -I$GOPATH/src
// Code generated by protoc-gen-gogo.
// source: my.proto
// DO NOT EDIT!
/*
Package my is a generated protocol buffer package.
It is generated from these files:
my.proto
It has these top-level messages:
Value
*/
package my
import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "github.com/gogo/protobuf/types"
import _ "github.com/gogo/protobuf/gogoproto"
import time "time"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
type Value struct {
Time *time.Time `protobuf:"bytes,1,opt,name=time,stdtime" json:"time,omitempty"`
}
func (m *Value) Reset() { *m = Value{} }
func (m *Value) String() string { return proto.CompactTextString(m) }
func (*Value) ProtoMessage() {}
func (*Value) Descriptor() ([]byte, []int) { return fileDescriptorMy, []int{0} }
func (m *Value) GetTime() *time.Time {
if m != nil {
return m.Time
}
return nil
}
func init() {
proto.RegisterType((*Value)(nil), "my.Value")
}
func init() { proto.RegisterFile("my.proto", fileDescriptorMy) }
var fileDescriptorMy = []byte{
// 138 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0xc8, 0xad, 0xd4, 0x2b,
0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xca, 0xad, 0x94, 0x92, 0x4f, 0xcf, 0xcf, 0x4f, 0xcf, 0x49,
0xd5, 0x07, 0x8b, 0x24, 0x95, 0xa6, 0xe9, 0x97, 0x64, 0xe6, 0xa6, 0x16, 0x97, 0x24, 0xe6, 0x16,
0x40, 0x14, 0x49, 0xe9, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xa7,
0xe7, 0xa7, 0xe7, 0x23, 0x54, 0x82, 0x78, 0x60, 0x0e, 0x98, 0x05, 0x51, 0xae, 0x64, 0xcb, 0xc5,
0x1a, 0x96, 0x98, 0x53, 0x9a, 0x2a, 0x64, 0xc2, 0xc5, 0x02, 0x32, 0x4a, 0x82, 0x51, 0x81, 0x51,
0x83, 0xdb, 0x48, 0x4a, 0x0f, 0x62, 0x8f, 0x1e, 0x4c, 0xb7, 0x5e, 0x08, 0xcc, 0x1e, 0x27, 0x96,
0x09, 0xf7, 0xe5, 0x19, 0x83, 0xc0, 0xaa, 0x93, 0xd8, 0xc0, 0xf2, 0xc6, 0x80, 0x00, 0x00, 0x00,
0xff, 0xff, 0x1a, 0xf9, 0xe3, 0x04, 0xa5, 0x00, 0x00, 0x00,
}
syntax = "proto3";
package my;
import "google/protobuf/timestamp.proto";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
message Value {
google.protobuf.Timestamp time = 1 [(gogoproto.stdtime) = true];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment