Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/slayers: remove unnecessary sub-slicing #4576

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading