Skip to content

Commit

Permalink
pkg/slayers: remove unnecessary sub-slicing (scionproto#4576)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiceatscion authored Jul 17, 2024
1 parent 8ba6b38 commit ad0d3bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/slayers/path/scion/decoded.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *Decoded) SerializeTo(b []byte) error {
return serrors.New("buffer too small to serialize path.", "expected", s.Len(),
"actual", len(b))
}
if err := s.PathMeta.SerializeTo(b[:MetaLen]); err != nil {
if err := s.PathMeta.SerializeTo(b); err != nil {
return err
}
offset := MetaLen
Expand Down
9 changes: 6 additions & 3 deletions pkg/slayers/path/scion/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ func (s *Raw) SerializeTo(b []byte) error {
}
// XXX(roosd): This modifies the underlying buffer. Consider writing to data
// directly.
if err := s.PathMeta.SerializeTo(s.Raw[:MetaLen]); err != nil {
// TODO(matzf, jiceatscion): it is not clear whether updating pathmeta in s.Raw is desirable
// or not. It migh be best to make that question moot by not keeping the path meta header as
// raw bytes at all. However that's a viral change.
if err := s.PathMeta.SerializeTo(s.Raw); err != nil {
return err
}
copy(b, s.Raw)
Expand Down Expand Up @@ -82,7 +85,7 @@ func (s *Raw) Reverse() (path.Path, error) {
// ToDecoded transforms a scion.Raw to a scion.Decoded.
func (s *Raw) ToDecoded() (*Decoded, error) {
// Serialize PathMeta to ensure potential changes are reflected Raw.
if err := s.PathMeta.SerializeTo(s.Raw[:MetaLen]); err != nil {
if err := s.PathMeta.SerializeTo(s.Raw); err != nil {
return nil, err
}
decoded := &Decoded{}
Expand All @@ -97,7 +100,7 @@ func (s *Raw) IncPath() error {
if err := s.Base.IncPath(); err != nil {
return err
}
return s.PathMeta.SerializeTo(s.Raw[:MetaLen])
return s.PathMeta.SerializeTo(s.Raw)
}

// GetInfoField returns the InfoField at a given index.
Expand Down

0 comments on commit ad0d3bc

Please sign in to comment.