forked from TrueCloudLab/frostfs-api-go
[#107] proto/test: Add oneof test
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
866db105ed
commit
981dc785f3
4 changed files with 469 additions and 27 deletions
297
util/proto/test/custom/test_frostfs.pb.go
generated
297
util/proto/test/custom/test_frostfs.pb.go
generated
|
@ -50,6 +50,135 @@ func (x *Primitives_SomeEnum) FromString(s string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
type Primitives_Aux struct {
|
||||
InnerField uint32 `json:"innerField"`
|
||||
}
|
||||
|
||||
var (
|
||||
_ encoding.ProtoMarshaler = (*Primitives_Aux)(nil)
|
||||
_ encoding.ProtoUnmarshaler = (*Primitives_Aux)(nil)
|
||||
_ json.Marshaler = (*Primitives_Aux)(nil)
|
||||
_ json.Unmarshaler = (*Primitives_Aux)(nil)
|
||||
)
|
||||
|
||||
// StableSize returns the size of x in protobuf format.
|
||||
//
|
||||
// Structures with the same field values have the same binary size.
|
||||
func (x *Primitives_Aux) StableSize() (size int) {
|
||||
if x == nil {
|
||||
return 0
|
||||
}
|
||||
size += proto.UInt32Size(1, x.InnerField)
|
||||
return size
|
||||
}
|
||||
|
||||
// MarshalProtobuf implements the encoding.ProtoMarshaler interface.
|
||||
func (x *Primitives_Aux) MarshalProtobuf(dst []byte) []byte {
|
||||
m := pool.MarshalerPool.Get()
|
||||
defer pool.MarshalerPool.Put(m)
|
||||
x.EmitProtobuf(m.MessageMarshaler())
|
||||
dst = m.Marshal(dst)
|
||||
return dst
|
||||
}
|
||||
|
||||
func (x *Primitives_Aux) EmitProtobuf(mm *easyproto.MessageMarshaler) {
|
||||
if x == nil {
|
||||
return
|
||||
}
|
||||
if x.InnerField != 0 {
|
||||
mm.AppendUint32(1, x.InnerField)
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalProtobuf implements the encoding.ProtoUnmarshaler interface.
|
||||
func (x *Primitives_Aux) UnmarshalProtobuf(src []byte) (err error) {
|
||||
var fc easyproto.FieldContext
|
||||
for len(src) > 0 {
|
||||
src, err = fc.NextField(src)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot read next field in %s", "Primitives_Aux")
|
||||
}
|
||||
switch fc.FieldNum {
|
||||
case 1: // InnerField
|
||||
data, ok := fc.Uint32()
|
||||
if !ok {
|
||||
return fmt.Errorf("cannot unmarshal field %s", "InnerField")
|
||||
}
|
||||
x.InnerField = data
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (x *Primitives_Aux) GetInnerField() uint32 {
|
||||
if x != nil {
|
||||
return x.InnerField
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func (x *Primitives_Aux) SetInnerField(v uint32) {
|
||||
x.InnerField = v
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaler interface.
|
||||
func (x *Primitives_Aux) MarshalJSON() ([]byte, error) {
|
||||
w := jwriter.Writer{}
|
||||
x.MarshalEasyJSON(&w)
|
||||
return w.Buffer.BuildBytes(), w.Error
|
||||
}
|
||||
func (x *Primitives_Aux) MarshalEasyJSON(out *jwriter.Writer) {
|
||||
if x == nil {
|
||||
out.RawString("null")
|
||||
return
|
||||
}
|
||||
out.RawByte('{')
|
||||
{
|
||||
const prefix string = ",\"innerField\":"
|
||||
out.RawString(prefix[1:])
|
||||
out.Uint32(x.InnerField)
|
||||
}
|
||||
out.RawByte('}')
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||
func (x *Primitives_Aux) UnmarshalJSON(data []byte) error {
|
||||
r := jlexer.Lexer{Data: data}
|
||||
x.UnmarshalEasyJSON(&r)
|
||||
return r.Error()
|
||||
}
|
||||
func (x *Primitives_Aux) UnmarshalEasyJSON(in *jlexer.Lexer) {
|
||||
isTopLevel := in.IsStart()
|
||||
if in.IsNull() {
|
||||
if isTopLevel {
|
||||
in.Consumed()
|
||||
}
|
||||
in.Skip()
|
||||
return
|
||||
}
|
||||
in.Delim('{')
|
||||
for !in.IsDelim('}') {
|
||||
key := in.UnsafeFieldName(false)
|
||||
in.WantColon()
|
||||
if in.IsNull() {
|
||||
in.Skip()
|
||||
in.WantComma()
|
||||
continue
|
||||
}
|
||||
switch key {
|
||||
case "innerField":
|
||||
{
|
||||
var f uint32
|
||||
f = in.Uint32()
|
||||
x.InnerField = f
|
||||
}
|
||||
}
|
||||
in.WantComma()
|
||||
}
|
||||
in.Delim('}')
|
||||
if isTopLevel {
|
||||
in.Consumed()
|
||||
}
|
||||
}
|
||||
|
||||
type Primitives struct {
|
||||
FieldA []byte `json:"fieldA"`
|
||||
FieldB string `json:"fieldB"`
|
||||
|
@ -62,6 +191,7 @@ type Primitives struct {
|
|||
FieldJ float64 `json:"fieldJ"`
|
||||
FieldK uint32 `json:"fieldK"`
|
||||
FieldH Primitives_SomeEnum `json:"fieldH"`
|
||||
FieldM isPrimitives_FieldM
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -89,6 +219,15 @@ func (x *Primitives) StableSize() (size int) {
|
|||
size += proto.Float64Size(206, x.FieldJ)
|
||||
size += proto.Fixed32Size(207, x.FieldK)
|
||||
size += proto.EnumSize(300, int32(x.FieldH))
|
||||
if inner, ok := x.FieldM.(*Primitives_FieldMa); ok {
|
||||
size += proto.BytesSize(401, inner.FieldMa)
|
||||
}
|
||||
if inner, ok := x.FieldM.(*Primitives_FieldMe); ok {
|
||||
size += proto.UInt32Size(402, inner.FieldMe)
|
||||
}
|
||||
if inner, ok := x.FieldM.(*Primitives_FieldAux); ok {
|
||||
size += proto.NestedStructureSize(403, inner.FieldAux)
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
|
@ -138,6 +277,21 @@ func (x *Primitives) EmitProtobuf(mm *easyproto.MessageMarshaler) {
|
|||
if int32(x.FieldH) != 0 {
|
||||
mm.AppendInt32(300, int32(x.FieldH))
|
||||
}
|
||||
if inner, ok := x.FieldM.(*Primitives_FieldMa); ok {
|
||||
if len(inner.FieldMa) != 0 {
|
||||
mm.AppendBytes(401, inner.FieldMa)
|
||||
}
|
||||
}
|
||||
if inner, ok := x.FieldM.(*Primitives_FieldMe); ok {
|
||||
if inner.FieldMe != 0 {
|
||||
mm.AppendUint32(402, inner.FieldMe)
|
||||
}
|
||||
}
|
||||
if inner, ok := x.FieldM.(*Primitives_FieldAux); ok {
|
||||
if inner.FieldAux != nil && inner.FieldAux.StableSize() != 0 {
|
||||
inner.FieldAux.EmitProtobuf(mm.AppendMessage(403))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalProtobuf implements the encoding.ProtoUnmarshaler interface.
|
||||
|
@ -215,6 +369,28 @@ func (x *Primitives) UnmarshalProtobuf(src []byte) (err error) {
|
|||
return fmt.Errorf("cannot unmarshal field %s", "FieldH")
|
||||
}
|
||||
x.FieldH = Primitives_SomeEnum(data)
|
||||
case 401: // FieldMa
|
||||
data, ok := fc.Bytes()
|
||||
if !ok {
|
||||
return fmt.Errorf("cannot unmarshal field %s", "FieldMa")
|
||||
}
|
||||
x.FieldM = &Primitives_FieldMa{FieldMa: data}
|
||||
case 402: // FieldMe
|
||||
data, ok := fc.Uint32()
|
||||
if !ok {
|
||||
return fmt.Errorf("cannot unmarshal field %s", "FieldMe")
|
||||
}
|
||||
x.FieldM = &Primitives_FieldMe{FieldMe: data}
|
||||
case 403: // FieldAux
|
||||
data, ok := fc.MessageData()
|
||||
if !ok {
|
||||
return fmt.Errorf("cannot unmarshal field %s", "FieldAux")
|
||||
}
|
||||
oneofField := &Primitives_FieldAux{FieldAux: new(Primitives_Aux)}
|
||||
if err := oneofField.FieldAux.UnmarshalProtobuf(data); err != nil {
|
||||
return fmt.Errorf("unmarshal: %w", err)
|
||||
}
|
||||
x.FieldM = oneofField
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -318,6 +494,60 @@ func (x *Primitives) GetFieldH() Primitives_SomeEnum {
|
|||
func (x *Primitives) SetFieldH(v Primitives_SomeEnum) {
|
||||
x.FieldH = v
|
||||
}
|
||||
func (x *Primitives) GetFieldM() isPrimitives_FieldM {
|
||||
if x != nil {
|
||||
return x.FieldM
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (x *Primitives) SetFieldM(v isPrimitives_FieldM) {
|
||||
x.FieldM = v
|
||||
}
|
||||
func (x *Primitives) GetFieldMa() []byte {
|
||||
if xx, ok := x.GetFieldM().(*Primitives_FieldMa); ok {
|
||||
return xx.FieldMa
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (x *Primitives) SetFieldMa(v *Primitives_FieldMa) {
|
||||
x.FieldM = v
|
||||
}
|
||||
func (x *Primitives_FieldMa) GetFieldMa() []byte {
|
||||
if x != nil {
|
||||
return x.FieldMa
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (x *Primitives_FieldMa) SetFieldMa(v []byte) {
|
||||
x.FieldMa = v
|
||||
}
|
||||
func (x *Primitives) GetFieldMe() uint32 {
|
||||
if xx, ok := x.GetFieldM().(*Primitives_FieldMe); ok {
|
||||
return xx.FieldMe
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func (x *Primitives) SetFieldMe(v *Primitives_FieldMe) {
|
||||
x.FieldM = v
|
||||
}
|
||||
func (x *Primitives_FieldMe) GetFieldMe() uint32 {
|
||||
if x != nil {
|
||||
return x.FieldMe
|
||||
}
|
||||
return 0
|
||||
}
|
||||
func (x *Primitives_FieldMe) SetFieldMe(v uint32) {
|
||||
x.FieldMe = v
|
||||
}
|
||||
func (x *Primitives) GetFieldAux() *Primitives_Aux {
|
||||
if xx, ok := x.GetFieldM().(*Primitives_FieldAux); ok {
|
||||
return xx.FieldAux
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (x *Primitives) SetFieldAux(v *Primitives_Aux) {
|
||||
x.FieldM = &Primitives_FieldAux{FieldAux: v}
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaler interface.
|
||||
func (x *Primitives) MarshalJSON() ([]byte, error) {
|
||||
|
@ -386,6 +616,26 @@ func (x *Primitives) MarshalEasyJSON(out *jwriter.Writer) {
|
|||
out.RawString(prefix)
|
||||
out.Int32(int32(x.FieldH))
|
||||
}
|
||||
switch xx := x.FieldM.(type) {
|
||||
case *Primitives_FieldMa:
|
||||
{
|
||||
const prefix string = ",\"fieldMa\":"
|
||||
out.RawString(prefix)
|
||||
out.Base64Bytes(xx.FieldMa)
|
||||
}
|
||||
case *Primitives_FieldMe:
|
||||
{
|
||||
const prefix string = ",\"fieldMe\":"
|
||||
out.RawString(prefix)
|
||||
out.Uint32(xx.FieldMe)
|
||||
}
|
||||
case *Primitives_FieldAux:
|
||||
{
|
||||
const prefix string = ",\"fieldAux\":"
|
||||
out.RawString(prefix)
|
||||
xx.FieldAux.MarshalEasyJSON(out)
|
||||
}
|
||||
}
|
||||
out.RawByte('}')
|
||||
}
|
||||
|
||||
|
@ -496,6 +746,31 @@ func (x *Primitives) UnmarshalEasyJSON(in *jlexer.Lexer) {
|
|||
f = parsedValue
|
||||
x.FieldH = f
|
||||
}
|
||||
case "fieldMa":
|
||||
xx := new(Primitives_FieldMa)
|
||||
x.FieldM = xx
|
||||
{
|
||||
var f []byte
|
||||
f = in.Bytes()
|
||||
xx.FieldMa = f
|
||||
}
|
||||
case "fieldMe":
|
||||
xx := new(Primitives_FieldMe)
|
||||
x.FieldM = xx
|
||||
{
|
||||
var f uint32
|
||||
f = in.Uint32()
|
||||
xx.FieldMe = f
|
||||
}
|
||||
case "fieldAux":
|
||||
xx := new(Primitives_FieldAux)
|
||||
x.FieldM = xx
|
||||
{
|
||||
var f *Primitives_Aux
|
||||
f = new(Primitives_Aux)
|
||||
f.UnmarshalEasyJSON(in)
|
||||
xx.FieldAux = f
|
||||
}
|
||||
}
|
||||
in.WantComma()
|
||||
}
|
||||
|
@ -505,6 +780,28 @@ func (x *Primitives) UnmarshalEasyJSON(in *jlexer.Lexer) {
|
|||
}
|
||||
}
|
||||
|
||||
type isPrimitives_FieldM interface {
|
||||
isPrimitives_FieldM()
|
||||
}
|
||||
|
||||
type Primitives_FieldMa struct {
|
||||
FieldMa []byte
|
||||
}
|
||||
|
||||
type Primitives_FieldMe struct {
|
||||
FieldMe uint32
|
||||
}
|
||||
|
||||
type Primitives_FieldAux struct {
|
||||
FieldAux *Primitives_Aux
|
||||
}
|
||||
|
||||
func (*Primitives_FieldMa) isPrimitives_FieldM() {}
|
||||
|
||||
func (*Primitives_FieldMe) isPrimitives_FieldM() {}
|
||||
|
||||
func (*Primitives_FieldAux) isPrimitives_FieldM() {}
|
||||
|
||||
type RepPrimitives struct {
|
||||
FieldA [][]byte `json:"fieldA"`
|
||||
FieldB []string `json:"fieldB"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue