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

fix the doc for prefix.BerTLV #257

Merged
merged 1 commit into from
Jul 26, 2023
Merged
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
13 changes: 7 additions & 6 deletions prefix/bertlv.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ var BerTLV = &berTLVPrefixer{}
type berTLVPrefixer struct{}

// EncodeLength encodes the data length provided into a slice of bytes
// according to the rules defined above.
// NOTE: Because BER-TLV lengths are encoded dynamically, the maxLen method
// argument is ignored.
// according to the rules defined above. If you want to avoid the max length
// check (e.g. for backwards compatibility), you can pass in 0 for maxLen (just
// don't specify it in the `Length` field of the spec)
func (p *berTLVPrefixer) EncodeLength(maxLen, dataLen int) ([]byte, error) {
// checking maxLen for a 0 is a way to disable check and also support
// backwards compatibility with the old contract that didn't have maxLen
Expand All @@ -48,9 +48,10 @@ func (p *berTLVPrefixer) EncodeLength(maxLen, dataLen int) ([]byte, error) {

// DecodeLength takes in a byte array and dynamically decodes its length based
// on the rules described above. On success, both the length of the TLV value
// as well as the number bytes read to decode the length are returned.
// NOTE: Because BER-TLV lengths are decoded dynamically, the maxLen method
// argument is ignored.
// as well as the number bytes read to decode the length are returned. If you
// want to avoid the max length check (e.g. for backwards compatibility), you
// can pass in 0 for maxLen (just don't specify it in the `Length` field of the
// spec)
func (p *berTLVPrefixer) DecodeLength(maxLen int, data []byte) (int, int, error) {
r := bytes.NewReader(data)

Expand Down
Loading