Skip to content

Commit

Permalink
remove embedded handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed Feb 13, 2023
1 parent 5f0db4d commit 732bcaf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 89 deletions.
6 changes: 2 additions & 4 deletions proto/amino/amino.proto
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ extend google.protobuf.FieldOptions {
// out == {"baz":""}
bool dont_omitempty = 11110005;

bool embed = 11110006;

string oneof_type_name = 11110007;
string oneof_type_name = 11110006;
}

extend google.protobuf.OneofOptions {
string oneof_field_name = 11110008;
string oneof_field_name = 11110007;
}
85 changes: 0 additions & 85 deletions x/tx/aminojson/json_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,65 +125,6 @@ func (aj AminoJSON) marshal(value protoreflect.Value, writer io.Writer) error {
}
}

// TODO
// merge with marshalMessage or if embed ends up not being needed delete it.
func (aj AminoJSON) marshalEmbedded(msg protoreflect.Message, writer io.Writer) (bool, error) {
fields := msg.Descriptor().Fields()
first := true
wrote := false
for i := 0; i < fields.Len(); i++ {
f := fields.Get(i)
v := msg.Get(f)
name := getFieldName(f)

if !msg.Has(f) {
if omitEmpty(f) {
continue
} else {
zv, found := aj.getZeroValue(f)
if found {
v = zv
}
}
}

if !first {
_, err := writer.Write([]byte(","))
if err != nil {
return wrote, err
}
}

err := jsonMarshal(writer, name)
wrote = true
if err != nil {
return wrote, err
}

_, err = writer.Write([]byte(":"))
if err != nil {
return wrote, err
}

// encode value
if encoder := aj.getFieldEncoding(f); encoder != nil {
err = encoder(aj, v, writer)
if err != nil {
return wrote, err
}
} else {
err = aj.marshal(v, writer)
if err != nil {
return wrote, err
}
}

first = false
}

return wrote, nil
}

func (aj AminoJSON) marshalMessage(msg protoreflect.Message, writer io.Writer) error {
if msg == nil {
return errors.New("nil message")
Expand Down Expand Up @@ -240,17 +181,6 @@ func (aj AminoJSON) marshalMessage(msg protoreflect.Message, writer io.Writer) e
}
}

if isFieldEmbedded(v, f) {
wrote, err := aj.marshalEmbedded(v.Message(), writer)
if err != nil {
return err
}
if wrote {
first = false
}
continue
}

if !first {
_, err = writer.Write([]byte(","))
if err != nil {
Expand Down Expand Up @@ -427,21 +357,6 @@ func (aj AminoJSON) getMessageEncoder(message protoreflect.Message) MessageEncod
return nil
}

func isFieldEmbedded(fieldValue protoreflect.Value, field protoreflect.FieldDescriptor) bool {
opts := field.Options()
if proto.HasExtension(opts, amino.E_Embed) {
embedded := proto.GetExtension(opts, amino.E_Embed).(bool)
switch fieldValue.Interface().(type) {
case protoreflect.Message:
return embedded
default:
fmt.Printf("WARN: field %s is not a message, but has the embedded option set to true. Ignoring option.\n", field.Name())
return false
}
}
return false
}

func (aj AminoJSON) getFieldEncoding(field protoreflect.FieldDescriptor) FieldEncoder {
opts := field.Options()
if proto.HasExtension(opts, amino.E_Encoding) {
Expand Down

0 comments on commit 732bcaf

Please sign in to comment.