зеркало из https://github.com/github/vitess-gh.git
bsongen: go/zk
This commit is contained in:
Родитель
3ee1262291
Коммит
c531c56cef
3
Makefile
3
Makefile
|
@ -73,3 +73,6 @@ bson:
|
|||
bsongen -file ./go/vt/binlog/proto/stream_event.go -type StreamEvent -o ./go/vt/binlog/proto/stream_event_bson.go
|
||||
bsongen -file ./go/zk/zkocc_structs.go -type ZkPath -o ./go/zk/zkpath_bson.go
|
||||
bsongen -file ./go/zk/zkocc_structs.go -type ZkPathV -o ./go/zk/zkpathv_bson.go
|
||||
bsongen -file ./go/zk/zkocc_structs.go -type ZkStat -o ./go/zk/zkstat_bson.go
|
||||
bsongen -file ./go/zk/zkocc_structs.go -type ZkNode -o ./go/zk/zknode_bson.go
|
||||
bsongen -file ./go/zk/zkocc_structs.go -type ZkNodeV -o ./go/zk/zknodev_bson.go
|
||||
|
|
|
@ -5,10 +5,11 @@
|
|||
package proto
|
||||
|
||||
import (
|
||||
"github.com/youtube/vitess/go/bson"
|
||||
"github.com/youtube/vitess/go/bytes2"
|
||||
|
||||
"bytes"
|
||||
|
||||
"github.com/youtube/vitess/go/bson"
|
||||
)
|
||||
|
||||
// DO NOT EDIT.
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
package proto
|
||||
|
||||
import (
|
||||
"github.com/youtube/vitess/go/bson"
|
||||
"github.com/youtube/vitess/go/bytes2"
|
||||
|
||||
"bytes"
|
||||
|
||||
"github.com/youtube/vitess/go/bson"
|
||||
)
|
||||
|
||||
// DO NOT EDIT.
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
// Copyright 2012, Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package zk
|
||||
|
||||
// DO NOT EDIT.
|
||||
// FILE GENERATED BY BSONGEN.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/youtube/vitess/go/bson"
|
||||
"github.com/youtube/vitess/go/bytes2"
|
||||
)
|
||||
|
||||
// MarshalBson bson-encodes ZkNode.
|
||||
func (zkNode *ZkNode) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
|
||||
bson.EncodeOptionalPrefix(buf, bson.Object, key)
|
||||
lenWriter := bson.NewLenWriter(buf)
|
||||
|
||||
bson.EncodeString(buf, "Path", zkNode.Path)
|
||||
bson.EncodeString(buf, "Data", zkNode.Data)
|
||||
zkNode.Stat.MarshalBson(buf, "Stat")
|
||||
// []string
|
||||
{
|
||||
bson.EncodePrefix(buf, bson.Array, "Children")
|
||||
lenWriter := bson.NewLenWriter(buf)
|
||||
for _i, _v1 := range zkNode.Children {
|
||||
bson.EncodeString(buf, bson.Itoa(_i), _v1)
|
||||
}
|
||||
lenWriter.Close()
|
||||
}
|
||||
bson.EncodeBool(buf, "Cached", zkNode.Cached)
|
||||
bson.EncodeBool(buf, "Stale", zkNode.Stale)
|
||||
|
||||
lenWriter.Close()
|
||||
}
|
||||
|
||||
// UnmarshalBson bson-decodes into ZkNode.
|
||||
func (zkNode *ZkNode) UnmarshalBson(buf *bytes.Buffer, kind byte) {
|
||||
switch kind {
|
||||
case bson.EOO, bson.Object:
|
||||
// valid
|
||||
case bson.Null:
|
||||
return
|
||||
default:
|
||||
panic(bson.NewBsonError("unexpected kind %v for ZkNode", kind))
|
||||
}
|
||||
bson.Next(buf, 4)
|
||||
|
||||
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
|
||||
switch bson.ReadCString(buf) {
|
||||
case "Path":
|
||||
zkNode.Path = bson.DecodeString(buf, kind)
|
||||
case "Data":
|
||||
zkNode.Data = bson.DecodeString(buf, kind)
|
||||
case "Stat":
|
||||
zkNode.Stat.UnmarshalBson(buf, kind)
|
||||
case "Children":
|
||||
// []string
|
||||
if kind != bson.Null {
|
||||
if kind != bson.Array {
|
||||
panic(bson.NewBsonError("unexpected kind %v for zkNode.Children", kind))
|
||||
}
|
||||
bson.Next(buf, 4)
|
||||
zkNode.Children = make([]string, 0, 8)
|
||||
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
|
||||
bson.SkipIndex(buf)
|
||||
var _v1 string
|
||||
_v1 = bson.DecodeString(buf, kind)
|
||||
zkNode.Children = append(zkNode.Children, _v1)
|
||||
}
|
||||
}
|
||||
case "Cached":
|
||||
zkNode.Cached = bson.DecodeBool(buf, kind)
|
||||
case "Stale":
|
||||
zkNode.Stale = bson.DecodeBool(buf, kind)
|
||||
default:
|
||||
bson.Skip(buf, kind)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
// Copyright 2012, Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package zk
|
||||
|
||||
// DO NOT EDIT.
|
||||
// FILE GENERATED BY BSONGEN.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/youtube/vitess/go/bson"
|
||||
"github.com/youtube/vitess/go/bytes2"
|
||||
)
|
||||
|
||||
// MarshalBson bson-encodes ZkNodeV.
|
||||
func (zkNodeV *ZkNodeV) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
|
||||
bson.EncodeOptionalPrefix(buf, bson.Object, key)
|
||||
lenWriter := bson.NewLenWriter(buf)
|
||||
|
||||
// []*ZkNode
|
||||
{
|
||||
bson.EncodePrefix(buf, bson.Array, "Nodes")
|
||||
lenWriter := bson.NewLenWriter(buf)
|
||||
for _i, _v1 := range zkNodeV.Nodes {
|
||||
// *ZkNode
|
||||
if _v1 == nil {
|
||||
bson.EncodePrefix(buf, bson.Null, bson.Itoa(_i))
|
||||
} else {
|
||||
(*_v1).MarshalBson(buf, bson.Itoa(_i))
|
||||
}
|
||||
}
|
||||
lenWriter.Close()
|
||||
}
|
||||
|
||||
lenWriter.Close()
|
||||
}
|
||||
|
||||
// UnmarshalBson bson-decodes into ZkNodeV.
|
||||
func (zkNodeV *ZkNodeV) UnmarshalBson(buf *bytes.Buffer, kind byte) {
|
||||
switch kind {
|
||||
case bson.EOO, bson.Object:
|
||||
// valid
|
||||
case bson.Null:
|
||||
return
|
||||
default:
|
||||
panic(bson.NewBsonError("unexpected kind %v for ZkNodeV", kind))
|
||||
}
|
||||
bson.Next(buf, 4)
|
||||
|
||||
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
|
||||
switch bson.ReadCString(buf) {
|
||||
case "Nodes":
|
||||
// []*ZkNode
|
||||
if kind != bson.Null {
|
||||
if kind != bson.Array {
|
||||
panic(bson.NewBsonError("unexpected kind %v for zkNodeV.Nodes", kind))
|
||||
}
|
||||
bson.Next(buf, 4)
|
||||
zkNodeV.Nodes = make([]*ZkNode, 0, 8)
|
||||
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
|
||||
bson.SkipIndex(buf)
|
||||
var _v1 *ZkNode
|
||||
// *ZkNode
|
||||
if kind != bson.Null {
|
||||
_v1 = new(ZkNode)
|
||||
(*_v1).UnmarshalBson(buf, kind)
|
||||
}
|
||||
zkNodeV.Nodes = append(zkNodeV.Nodes, _v1)
|
||||
}
|
||||
}
|
||||
default:
|
||||
bson.Skip(buf, kind)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,176 +0,0 @@
|
|||
// Copyright 2012, Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package zk
|
||||
|
||||
// Contains the bson custom marshaler / unmarshaler.
|
||||
// Note this is not required, but makes the code faster.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/youtube/vitess/go/bson"
|
||||
"github.com/youtube/vitess/go/bytes2"
|
||||
)
|
||||
|
||||
func (zkStat *ZkStat) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
|
||||
bson.EncodeOptionalPrefix(buf, bson.Object, key)
|
||||
lenWriter := bson.NewLenWriter(buf)
|
||||
|
||||
bson.EncodeInt64(buf, "Czxid", zkStat.czxid)
|
||||
bson.EncodeInt64(buf, "Mzxid", zkStat.mzxid)
|
||||
bson.EncodeTime(buf, "CTime", zkStat.cTime)
|
||||
bson.EncodeTime(buf, "MTime", zkStat.mTime)
|
||||
bson.EncodeInt32(buf, "Version", int32(zkStat.version))
|
||||
bson.EncodeInt32(buf, "CVersion", int32(zkStat.cVersion))
|
||||
bson.EncodeInt32(buf, "AVersion", int32(zkStat.aVersion))
|
||||
bson.EncodeInt64(buf, "EphemeralOwner", zkStat.ephemeralOwner)
|
||||
bson.EncodeInt32(buf, "DataLength", int32(zkStat.dataLength))
|
||||
bson.EncodeInt32(buf, "NumChildren", int32(zkStat.numChildren))
|
||||
bson.EncodeInt64(buf, "Pzxid", zkStat.pzxid)
|
||||
|
||||
lenWriter.Close()
|
||||
}
|
||||
|
||||
func (zkStat *ZkStat) UnmarshalBson(buf *bytes.Buffer, kind byte) {
|
||||
bson.VerifyObject(kind)
|
||||
bson.Next(buf, 4)
|
||||
|
||||
kind = bson.NextByte(buf)
|
||||
for kind != bson.EOO {
|
||||
key := bson.ReadCString(buf)
|
||||
switch key {
|
||||
case "Czxid":
|
||||
zkStat.czxid = bson.DecodeInt64(buf, kind)
|
||||
case "Mzxid":
|
||||
zkStat.mzxid = bson.DecodeInt64(buf, kind)
|
||||
case "CTime":
|
||||
zkStat.cTime = bson.DecodeTime(buf, kind)
|
||||
case "MTime":
|
||||
zkStat.mTime = bson.DecodeTime(buf, kind)
|
||||
case "Version":
|
||||
zkStat.version = bson.DecodeInt(buf, kind)
|
||||
case "CVersion":
|
||||
zkStat.cVersion = bson.DecodeInt(buf, kind)
|
||||
case "AVersion":
|
||||
zkStat.aVersion = bson.DecodeInt(buf, kind)
|
||||
case "EphemeralOwner":
|
||||
zkStat.ephemeralOwner = bson.DecodeInt64(buf, kind)
|
||||
case "DataLength":
|
||||
zkStat.dataLength = bson.DecodeInt(buf, kind)
|
||||
case "NumChildren":
|
||||
zkStat.numChildren = bson.DecodeInt(buf, kind)
|
||||
case "Pzxid":
|
||||
zkStat.pzxid = bson.DecodeInt64(buf, kind)
|
||||
default:
|
||||
bson.Skip(buf, kind)
|
||||
}
|
||||
kind = bson.NextByte(buf)
|
||||
}
|
||||
}
|
||||
|
||||
func (zkNode *ZkNode) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
|
||||
bson.EncodeOptionalPrefix(buf, bson.Object, key)
|
||||
lenWriter := bson.NewLenWriter(buf)
|
||||
|
||||
bson.EncodeString(buf, "Path", zkNode.Path)
|
||||
bson.EncodeString(buf, "Data", zkNode.Data)
|
||||
zkNode.Stat.MarshalBson(buf, "Stat")
|
||||
bson.EncodeStringArray(buf, "Children", zkNode.Children)
|
||||
bson.EncodeBool(buf, "Cached", zkNode.Cached)
|
||||
bson.EncodeBool(buf, "Stale", zkNode.Stale)
|
||||
|
||||
lenWriter.Close()
|
||||
}
|
||||
|
||||
func (zkNode *ZkNode) UnmarshalBson(buf *bytes.Buffer, kind byte) {
|
||||
bson.VerifyObject(kind)
|
||||
bson.Next(buf, 4)
|
||||
|
||||
kind = bson.NextByte(buf)
|
||||
for kind != bson.EOO {
|
||||
key := bson.ReadCString(buf)
|
||||
switch key {
|
||||
case "Path":
|
||||
zkNode.Path = bson.DecodeString(buf, kind)
|
||||
case "Data":
|
||||
zkNode.Data = bson.DecodeString(buf, kind)
|
||||
case "Stat":
|
||||
if kind != bson.Object {
|
||||
panic(bson.NewBsonError("Unexpected data type %v for Stat", kind))
|
||||
}
|
||||
zkNode.Stat.UnmarshalBson(buf, kind)
|
||||
case "Children":
|
||||
zkNode.Children = bson.DecodeStringArray(buf, kind)
|
||||
case "Cached":
|
||||
zkNode.Cached = bson.DecodeBool(buf, kind)
|
||||
case "Stale":
|
||||
zkNode.Stale = bson.DecodeBool(buf, kind)
|
||||
default:
|
||||
bson.Skip(buf, kind)
|
||||
}
|
||||
kind = bson.NextByte(buf)
|
||||
}
|
||||
}
|
||||
|
||||
func marshalZkNodeArray(buf *bytes2.ChunkedWriter, name string, values []*ZkNode) {
|
||||
bson.EncodePrefix(buf, bson.Array, name)
|
||||
lenWriter := bson.NewLenWriter(buf)
|
||||
for i, val := range values {
|
||||
val.MarshalBson(buf, bson.Itoa(i))
|
||||
}
|
||||
lenWriter.Close()
|
||||
}
|
||||
|
||||
func unmarshalZkNodeArray(buf *bytes.Buffer, name string, kind byte) []*ZkNode {
|
||||
switch kind {
|
||||
case bson.Array:
|
||||
// valid
|
||||
case bson.Null:
|
||||
return nil
|
||||
default:
|
||||
panic(bson.NewBsonError("Unexpected data type %v for %v", kind, name))
|
||||
}
|
||||
|
||||
bson.Next(buf, 4)
|
||||
values := make([]*ZkNode, 0, 8)
|
||||
kind = bson.NextByte(buf)
|
||||
for kind != bson.EOO {
|
||||
if kind != bson.Object {
|
||||
panic(bson.NewBsonError("Unexpected data type %v for %v", kind, name))
|
||||
}
|
||||
bson.SkipIndex(buf)
|
||||
zkNode := &ZkNode{}
|
||||
zkNode.UnmarshalBson(buf, kind)
|
||||
values = append(values, zkNode)
|
||||
kind = bson.NextByte(buf)
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func (zkNodeV *ZkNodeV) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
|
||||
bson.EncodeOptionalPrefix(buf, bson.Object, key)
|
||||
lenWriter := bson.NewLenWriter(buf)
|
||||
|
||||
marshalZkNodeArray(buf, "Nodes", zkNodeV.Nodes)
|
||||
|
||||
lenWriter.Close()
|
||||
}
|
||||
|
||||
func (zkNodeV *ZkNodeV) UnmarshalBson(buf *bytes.Buffer, kind byte) {
|
||||
bson.VerifyObject(kind)
|
||||
bson.Next(buf, 4)
|
||||
|
||||
kind = bson.NextByte(buf)
|
||||
for kind != bson.EOO {
|
||||
key := bson.ReadCString(buf)
|
||||
switch key {
|
||||
case "Nodes":
|
||||
zkNodeV.Nodes = unmarshalZkNodeArray(buf, "ZkNodeV.Nodes", kind)
|
||||
default:
|
||||
bson.Skip(buf, kind)
|
||||
}
|
||||
kind = bson.NextByte(buf)
|
||||
}
|
||||
}
|
|
@ -11,17 +11,17 @@ import (
|
|||
)
|
||||
|
||||
type ZkStat struct {
|
||||
czxid int64
|
||||
mzxid int64
|
||||
cTime time.Time
|
||||
mTime time.Time
|
||||
version int
|
||||
cVersion int
|
||||
aVersion int
|
||||
ephemeralOwner int64
|
||||
dataLength int
|
||||
numChildren int
|
||||
pzxid int64
|
||||
czxid int64 `bson:"Czxid"`
|
||||
mzxid int64 `bson:"Mzxid"`
|
||||
cTime time.Time `bson:"CTime"`
|
||||
mTime time.Time `bson:"MTime"`
|
||||
version int `bson:"Version"`
|
||||
cVersion int `bson:"CVersion"`
|
||||
aVersion int `bson:"AVerion"`
|
||||
ephemeralOwner int64 `bson:"EphemeralOwner"`
|
||||
dataLength int `bson:"DataLength"`
|
||||
numChildren int `bson:"NumChildren"`
|
||||
pzxid int64 `bson:"Pzxid"`
|
||||
}
|
||||
|
||||
type ZkPath struct {
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
// Copyright 2012, Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package zk
|
||||
|
||||
// DO NOT EDIT.
|
||||
// FILE GENERATED BY BSONGEN.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/youtube/vitess/go/bson"
|
||||
"github.com/youtube/vitess/go/bytes2"
|
||||
)
|
||||
|
||||
// MarshalBson bson-encodes ZkStat.
|
||||
func (zkStat *ZkStat) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
|
||||
bson.EncodeOptionalPrefix(buf, bson.Object, key)
|
||||
lenWriter := bson.NewLenWriter(buf)
|
||||
|
||||
bson.EncodeInt64(buf, "Czxid", zkStat.czxid)
|
||||
bson.EncodeInt64(buf, "Mzxid", zkStat.mzxid)
|
||||
bson.EncodeTime(buf, "CTime", zkStat.cTime)
|
||||
bson.EncodeTime(buf, "MTime", zkStat.mTime)
|
||||
bson.EncodeInt(buf, "Version", zkStat.version)
|
||||
bson.EncodeInt(buf, "CVersion", zkStat.cVersion)
|
||||
bson.EncodeInt(buf, "AVerion", zkStat.aVersion)
|
||||
bson.EncodeInt64(buf, "EphemeralOwner", zkStat.ephemeralOwner)
|
||||
bson.EncodeInt(buf, "DataLength", zkStat.dataLength)
|
||||
bson.EncodeInt(buf, "NumChildren", zkStat.numChildren)
|
||||
bson.EncodeInt64(buf, "Pzxid", zkStat.pzxid)
|
||||
|
||||
lenWriter.Close()
|
||||
}
|
||||
|
||||
// UnmarshalBson bson-decodes into ZkStat.
|
||||
func (zkStat *ZkStat) UnmarshalBson(buf *bytes.Buffer, kind byte) {
|
||||
switch kind {
|
||||
case bson.EOO, bson.Object:
|
||||
// valid
|
||||
case bson.Null:
|
||||
return
|
||||
default:
|
||||
panic(bson.NewBsonError("unexpected kind %v for ZkStat", kind))
|
||||
}
|
||||
bson.Next(buf, 4)
|
||||
|
||||
for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
|
||||
switch bson.ReadCString(buf) {
|
||||
case "Czxid":
|
||||
zkStat.czxid = bson.DecodeInt64(buf, kind)
|
||||
case "Mzxid":
|
||||
zkStat.mzxid = bson.DecodeInt64(buf, kind)
|
||||
case "CTime":
|
||||
zkStat.cTime = bson.DecodeTime(buf, kind)
|
||||
case "MTime":
|
||||
zkStat.mTime = bson.DecodeTime(buf, kind)
|
||||
case "Version":
|
||||
zkStat.version = bson.DecodeInt(buf, kind)
|
||||
case "CVersion":
|
||||
zkStat.cVersion = bson.DecodeInt(buf, kind)
|
||||
case "AVerion":
|
||||
zkStat.aVersion = bson.DecodeInt(buf, kind)
|
||||
case "EphemeralOwner":
|
||||
zkStat.ephemeralOwner = bson.DecodeInt64(buf, kind)
|
||||
case "DataLength":
|
||||
zkStat.dataLength = bson.DecodeInt(buf, kind)
|
||||
case "NumChildren":
|
||||
zkStat.numChildren = bson.DecodeInt(buf, kind)
|
||||
case "Pzxid":
|
||||
zkStat.pzxid = bson.DecodeInt64(buf, kind)
|
||||
default:
|
||||
bson.Skip(buf, kind)
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче