From 743b60039393a75e44d4cd305ddd96f6269b05f8 Mon Sep 17 00:00:00 2001 From: Pavel Gabriel Date: Wed, 26 Jul 2023 14:07:50 +0200 Subject: [PATCH] fix the doc for prefix.BerTLV (#257) --- prefix/bertlv.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/prefix/bertlv.go b/prefix/bertlv.go index e5d8340..5e264b0 100644 --- a/prefix/bertlv.go +++ b/prefix/bertlv.go @@ -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 @@ -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)