Fix string len encoding

This commit is contained in:
gagliardetto 2021-12-24 14:55:23 +01:00
parent e5f3c23fae
commit 843d863a52
4 changed files with 48 additions and 8 deletions

View File

@ -177,7 +177,11 @@ func (inst AllocateWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder) erro
} }
// Serialize `Seed` param: // Serialize `Seed` param:
{ {
err := encoder.Encode(*inst.Seed) err := encoder.WriteUint64(uint64(len(*inst.Seed)), binary.LittleEndian)
if err != nil {
return err
}
err = encoder.WriteBytes([]byte(*inst.Seed), false)
if err != nil { if err != nil {
return err return err
} }
@ -209,10 +213,16 @@ func (inst *AllocateWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decoder) e
} }
// Deserialize `Seed` param: // Deserialize `Seed` param:
{ {
err := decoder.Decode(&inst.Seed) length, err := decoder.ReadUint64(binary.LittleEndian)
if err != nil { if err != nil {
return err return err
} }
bytes, err := decoder.ReadNBytes(int(length))
if err != nil {
return err
}
value := string(bytes)
inst.Seed = &value
} }
// Deserialize `Space` param: // Deserialize `Space` param:
{ {

View File

@ -164,7 +164,11 @@ func (inst AssignWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder) error
} }
// Serialize `Seed` param: // Serialize `Seed` param:
{ {
err := encoder.Encode(*inst.Seed) err := encoder.WriteUint64(uint64(len(*inst.Seed)), binary.LittleEndian)
if err != nil {
return err
}
err = encoder.WriteBytes([]byte(*inst.Seed), false)
if err != nil { if err != nil {
return err return err
} }
@ -189,10 +193,16 @@ func (inst *AssignWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decoder) err
} }
// Deserialize `Seed` param: // Deserialize `Seed` param:
{ {
err := decoder.Decode(&inst.Seed) length, err := decoder.ReadUint64(binary.LittleEndian)
if err != nil { if err != nil {
return err return err
} }
bytes, err := decoder.ReadNBytes(int(length))
if err != nil {
return err
}
value := string(bytes)
inst.Seed = &value
} }
// Deserialize `Owner` param: // Deserialize `Owner` param:
{ {

View File

@ -212,7 +212,11 @@ func (inst CreateAccountWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder)
} }
// Serialize `Seed` param: // Serialize `Seed` param:
{ {
err := encoder.Encode(*inst.Seed) err := encoder.WriteUint64(uint64(len(*inst.Seed)), binary.LittleEndian)
if err != nil {
return err
}
err = encoder.WriteBytes([]byte(*inst.Seed), false)
if err != nil { if err != nil {
return err return err
} }
@ -251,10 +255,16 @@ func (inst *CreateAccountWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decod
} }
// Deserialize `Seed` param: // Deserialize `Seed` param:
{ {
err := decoder.Decode(&inst.Seed) length, err := decoder.ReadUint64(binary.LittleEndian)
if err != nil { if err != nil {
return err return err
} }
bytes, err := decoder.ReadNBytes(int(length))
if err != nil {
return err
}
value := string(bytes)
inst.Seed = &value
} }
// Deserialize `Lamports` param: // Deserialize `Lamports` param:
{ {

View File

@ -178,7 +178,11 @@ func (inst TransferWithSeed) MarshalWithEncoder(encoder *ag_binary.Encoder) erro
} }
// Serialize `FromSeed` param: // Serialize `FromSeed` param:
{ {
err := encoder.Encode(*inst.FromSeed) err := encoder.WriteUint64(uint64(len(*inst.FromSeed)), binary.LittleEndian)
if err != nil {
return err
}
err = encoder.WriteBytes([]byte(*inst.FromSeed), false)
if err != nil { if err != nil {
return err return err
} }
@ -203,10 +207,16 @@ func (inst *TransferWithSeed) UnmarshalWithDecoder(decoder *ag_binary.Decoder) e
} }
// Deserialize `FromSeed` param: // Deserialize `FromSeed` param:
{ {
err := decoder.Decode(&inst.FromSeed) length, err := decoder.ReadUint64(binary.LittleEndian)
if err != nil { if err != nil {
return err return err
} }
bytes, err := decoder.ReadNBytes(int(length))
if err != nil {
return err
}
value := string(bytes)
inst.FromSeed = &value
} }
// Deserialize `FromOwner` param: // Deserialize `FromOwner` param:
{ {