Skip to content

v3: refactor Stream struct #471

@bigbes

Description

@bigbes

Summary

In v3, we want to unexport both fields of the Stream struct to enforce encapsulation and prevent misuse. Access to the stream ID should be provided via a method instead.

Current Definition

type Stream struct {
	Id   uint64
	Conn *Connection
}

Both fields are public, which allows unsafe direct access or mutation (e.g., stream.Conn = nil).

Proposed Change

type Stream struct {
	id   uint64
	conn *Connection
}

func (s *Stream) Id() uint64 { return s.id }
// No accessor for conn — it's internal only.
  • Make both fields unexported (id, conn).
  • Add a read-only Id() method to expose the stream ID.
  • Do not expose conn—users should never need to access the underlying connection directly.

Checklist

  • Update Stream struct fields to be unexported.
  • Add Id() method.
  • Update internal code to use s.id/s.conn.
  • Verify no external code relies on direct field access (this is a v3 breaking change).
    (meaning add CHANGELOG.md and MIGRATION.md records)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions