Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pelletier committed Sep 19, 2023
1 parent dd6f6ff commit f10d5bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 6 additions & 5 deletions internal/serde/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,8 @@ func serializePointedAt(s *Serializer, t reflect.Type, p unsafe.Pointer) {
// Check the region of this pointer.
r := s.containers.of(p)

// If this pointer does not belong to any region or is the container of
// the region, write a negative offset to flag it is on its own, and
// write its data.
// If this pointer does not belong to any region, write a negative
// offset to flag it is on its own, and write its data.
if !r.valid() {
serializeVarint(s, -1)
SerializeAny(s, t, p)
Expand All @@ -244,8 +243,10 @@ func serializePointedAt(s *Serializer, t reflect.Type, p unsafe.Pointer) {
// Write the type of the container.
serializeType(s, r.typ)

// Serialize the parent.

// Serialize the parent. If offset is zero, we reuse the id to store the
// parent. We could have a more compact representation here, but right
// now we need this since the pointers <> id map in the serializer does
// not discriminate between the container and the first element of it.
if offset == 0 {
serializeVarint(s, int(id))
serializeVarint(s, -1)
Expand Down
7 changes: 3 additions & 4 deletions internal/serde/serde.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ func (d *Deserializer) store(i sID, p unsafe.Pointer) {
// This mechanism allows writing shared data only once. The actual value is
// written the first time a given pointer ID is encountered.
//
// The regions value contains ranges of memory held by container types. They are
// the values that actually own memory: basic types (bool, numbers), structs,
// and arrays.
// The containers value has ranges of memory held by container types. They are
// the values that actually own memory: structs and arrays.
//
// Serialization starts with scanning the graph of values to find all the
// containers and add the range of memory they occupy into the map. Regions
Expand All @@ -104,7 +103,7 @@ func (d *Deserializer) store(i sID, p unsafe.Pointer) {
// }
// }
//
// creates only one region: the struct X. Both struct Y and the int are
// creates only one container: the struct X. Both struct Y and the int are
// containers, but they are included in the region of struct X.
//
// Those two mechanisms allow the deserialization of pointers that point to
Expand Down

0 comments on commit f10d5bc

Please sign in to comment.