Skip to content

Commit

Permalink
Store 8 byte size
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Nov 20, 2023
1 parent 1b387b2 commit ead4796
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions types/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ func deserializeType(d *Deserializer) reflect.Type {
func serializeAny(s *Serializer, t reflect.Type, p unsafe.Pointer) {
if serde, ok := s.serdes.serdeOf(t); ok {
offset := len(s.b)
s.b = append(s.b, 0, 0, 0, 0) // store a 32-bit size placeholder
s.b = append(s.b, 0, 0, 0, 0, 0, 0, 0, 0) // store a 64-bit size placeholder
serde.ser(s, t, p)
size := len(s.b) - offset
if int64(size) > math.MaxUint32 {
panic("overflow")
}
binary.LittleEndian.PutUint32(s.b[offset:], uint32(size))
binary.LittleEndian.PutUint64(s.b[offset:], uint64(len(s.b)-offset))
return
}

Expand Down Expand Up @@ -102,7 +98,7 @@ func serializeAny(s *Serializer, t reflect.Type, p unsafe.Pointer) {

func deserializeAny(d *Deserializer, t reflect.Type, p unsafe.Pointer) {
if serde, ok := d.serdes.serdeOf(t); ok {
d.b = d.b[4:] // skip size prefix
d.b = d.b[8:] // skip size prefix
serde.des(d, t, p)
return
}
Expand Down

0 comments on commit ead4796

Please sign in to comment.