Skip to content

Commit 035b43f

Browse files
committed
WIP: committing feature complete code with debug output & a bunch of
comments & todos for @marbar3778 to catch up Signed-off-by: Ismail Khoffi <[email protected]>
1 parent c774dcb commit 035b43f

File tree

6 files changed

+260
-69
lines changed

6 files changed

+260
-69
lines changed

amino.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -230,37 +230,16 @@ func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error) {
230230
// If registered concrete, prepend prefix bytes by wrapping
231231
// message in RegisteredAny:
232232
if info.Registered {
233-
fmt.Println(info.InterfaceInfo.AlwaysDisambiguate)
234-
fmt.Println(info.Name)
235-
fmt.Println(info.AlwaysDisambiguate)
236-
fmt.Println(len(info.Implementers[info.Prefix]) > 1)
237-
// if one of the interfaces this concrete type implements
238-
// has set the AlwaysDisambiguate flag, we need to disambiguate.
239-
isDisamb, _ := shouldDisamb(cdc, info)
240-
disfix := make([]byte, 0)
241-
if isDisamb {
242-
disfix = append([]byte{0x00}, info.Disamb.Bytes()...)
243-
}
244-
disfix = append(disfix, info.Prefix.Bytes()...)
245-
return MarshalBinaryBare(RegisteredAny{
246-
AminoPreOrDisfix: disfix,
233+
rAny := RegisteredAny{
234+
AminoPreOrDisfix: info.Prefix.Bytes(),
247235
Value: bz,
248-
})
236+
}
237+
return MarshalBinaryBare(rAny)
249238
}
250239

251240
return bz, nil
252241
}
253242

254-
func shouldDisamb(cdc *Codec, info *TypeInfo) (bool, *TypeInfo) {
255-
for _, iinfo := range cdc.interfaceInfos {
256-
if info.PtrToType.Implements(iinfo.Type) && iinfo.AlwaysDisambiguate {
257-
fmt.Println("DISAMB", iinfo.Name)
258-
return true, iinfo
259-
}
260-
}
261-
return false, nil
262-
}
263-
264243
// TODO: extensively document this!
265244
//
266245
// This will be compatible to the following proto3 message:

binary-encode.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,12 @@ func (cdc *Codec) encodeReflectBinaryInterface(w io.Writer, iinfo *TypeInfo, rv
213213
}
214214
disfix := make([]byte, 0)
215215
if needDisamb {
216+
// 0x00 indicates that these are disfix bytes
216217
disfix = append([]byte{0x00}, cinfo.Disamb[:]...)
217218
}
218219
disfix = append(disfix, cinfo.Prefix.Bytes()...)
219220
aminoAny := &RegisteredAny{AminoPreOrDisfix: disfix}
221+
fmt.Printf("disfix = %#v\n", disfix)
220222
// Write actual concrete value.
221223
err = cdc.encodeReflectBinary(buf, cinfo, crv, fopts, true)
222224
if err != nil {

reflect_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func TestCodecMarhsalBinaryBareRegisteredAndDisamb(t *testing.T) {
192192

193193
bz, err := cdc.MarshalBinaryBare(struct{ tests.Interface1 }{tests.Concrete1{}})
194194
assert.NoError(t, err, "correctly registered")
195-
assert.Equal(t, []byte{0xa, 0x6, 0xa, 0x4, 0xe3, 0xda, 0xb8, 0x33}, bz,
195+
assert.Equal(t, []byte{0xa, 0xa, 0xa, 0x8, 0x0, 0x12, 0xb5, 0x86, 0xe3, 0xda, 0xb8, 0x33}, bz,
196196
"prefix bytes did not match")
197197
}
198198

tests/proto3/proto/compat.pb.go

Lines changed: 214 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/proto3/proto/compat.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ message AminoRegisteredAny {
8484
bytes Value = 2;
8585
}
8686

87+
message EmbeddedRegisteredAny {
88+
AminoRegisteredAny F1 = 1;
89+
}
90+
8791
message SimpleMsg {
8892
string Message = 1;
8993
int64 Height = 2;

0 commit comments

Comments
 (0)