func parseBinaryAnnotation(lengthByte byte, r io.Reader) (Value, error) {
	// 0xE as the high byte has two potential uses, one for annotations and one for the
	// start of the binary version marker.  We are going to be optimistic and assume that
	// 0xE0 is for the BVM and all other values for the low nibble is for annotations.
	if lengthByte == 0 {
		return parseBinaryVersionMarker(r)
	}

	if lengthByte < 3 {
		return nil, errors.Errorf("length must be at least 3 for an annotation wrapper, found %d", lengthByte)
	}

	numBytes, errLength := determineLength32(lengthByte, r)
	if errLength != nil {
		return nil, errors.WithMessage(errLength, "unable to parse length of annotation")
	}

	data := make([]byte, numBytes)
	if n, err := r.Read(data); err != nil || n != int(numBytes) {
		return nil, errors.Errorf("unable to read annotation - read %d bytes of %d with err: %v", n, numBytes, err)
	}

	dataReader := bytes.NewReader(data)
	annLen, errAnnLen := readVarUInt16(dataReader)
	if errAnnLen != nil {
		return nil, errors.WithMessage(errAnnLen, "unable to determine annotation symbol length")
	}

	if annLen == 0 || uint32(annLen) >= numBytes {
		return nil, errors.Errorf("invalid lengths for annotation - field length is %d while annotation symbols length is %d", numBytes, annLen)
	}

	annData := make([]byte, annLen)
	// We've already verified lengths and are basically performing a copy to
	// a pre-allocated byte slice.  There is no error to catch.
	_, _ = dataReader.Read(annData)

	annReader := bytes.NewReader(annData)
	var annotations []Symbol
	for annReader.Len() > 0 {
		symbol, errSymbol := readVarUInt32(annReader)
		if errSymbol != nil {
			return nil, errors.WithMessage(errSymbol, "unable to read annotation symbol")
		}
		annotations = append(annotations, Symbol{id: int32(symbol)})
	}

	// Since an annotation is a container for a single value there isn't a need to
	// pre-read the contents so that we know when to stop.
	value, errValue := parseNextBinaryValue(annotations, dataReader)
	if errValue != nil {
		return nil, errors.WithMessage(errValue, "unable to read annotation value")
	}

	if dataReader.Len() > 0 {
		return nil, errors.Errorf("annotation declared %d bytes but there are %d bytes left", numBytes, dataReader.Len())
	}

	if _, ok := value.(padding); ok {
		return nil, errors.New("annotation on padding is not legal")
	}

	return value, nil
}
// parseBinaryAnnotation reads the annotation and the value that it is
// annotating.  If the lengthByte is zero, then this is treated as the
// first byte of a Binary Version Marker.
parseBinaryAnnotation reads the annotation and the value that it is
annotating.  If the lengthByte is zero, then this is treated as the
first byte of a Binary Version Marker.
// parseBinaryAnnotation reads the annotation and the value that it is // annotating . If the lengthByte is zero then this is treated as the // first byte of a Binary Version Marker .
func parseBinaryAnnotation(lengthByte byte, r io.Reader) (Value, error) {
	if lengthByte == 0 {
		return parseBinaryVersionMarker(r)
	}
	if lengthByte < 3 {
		return nil, errors.Errorf("length must be at least 3 for an annotation wrapper, found %d", lengthByte)
	}
	numBytes, errLength := determineLength32(lengthByte, r)
	if errLength != nil {
		return nil, errors.WithMessage(errLength, "unable to parse length of annotation")
	}
	data := make([]byte, numBytes)
	if n, err := r.Read(data); err != nil || n != int(numBytes) {
		return nil, errors.Errorf("unable to read annotation - read %d bytes of %d with err: %v", n, numBytes, err)
	}
	dataReader := bytes.NewReader(data)
	annLen, errAnnLen := readVarUInt16(dataReader)
	if errAnnLen != nil {
		return nil, errors.WithMessage(errAnnLen, "unable to determine annotation symbol length")
	}
	if annLen == 0 || uint32(annLen) >= numBytes {
		return nil, errors.Errorf("invalid lengths for annotation - field length is %d while annotation symbols length is %d", numBytes, annLen)
	}
	annData := make([]byte, annLen)
	_, _ = dataReader.Read(annData)
	annReader := bytes.NewReader(annData)
	var annotations []Symbol
	for annReader.Len() > 0 {
		symbol, errSymbol := readVarUInt32(annReader)
		if errSymbol != nil {
			return nil, errors.WithMessage(errSymbol, "unable to read annotation symbol")
		}
		annotations = append(annotations, Symbol{id: int32(symbol)})
	}
	value, errValue := parseNextBinaryValue(annotations, dataReader)
	if errValue != nil {
		return nil, errors.WithMessage(errValue, "unable to read annotation value")
	}
	if dataReader.Len() > 0 {
		return nil, errors.Errorf("annotation declared %d bytes but there are %d bytes left", numBytes, dataReader.Len())
	}
	if _, ok := value.(padding); ok {
		return nil, errors.New("annotation on padding is not legal")
	}
	return value, nil
}
func parseBinaryAnnotation ( lengthByte byte , r io . Reader ) ( Value , error ) { if lengthByte == 0 { return parseBinaryVersionMarker ( r ) } if lengthByte < 3 { return nil , errors . Errorf ( " " , lengthByte ) } numBytes , errLength := determineLength32 ( lengthByte , r ) if errLength != nil { return nil , errors . WithMessage ( errLength , " " ) } data := make ( [ ] byte , numBytes ) if n , err := r . Read ( data ) ; err != nil || n != int ( numBytes ) { return nil , errors . Errorf ( " " , n , numBytes , err ) } dataReader := bytes . NewReader ( data ) annLen , errAnnLen := readVarUInt16 ( dataReader ) if errAnnLen != nil { return nil , errors . WithMessage ( errAnnLen , " " ) } if annLen == 0 || uint32 ( annLen ) >= numBytes { return nil , errors . Errorf ( " " , numBytes , annLen ) } annData := make ( [ ] byte , annLen ) _ , _ = dataReader . Read ( annData ) annReader := bytes . NewReader ( annData ) var annotations [ ] Symbol for annReader . Len ( ) > 0 { symbol , errSymbol := readVarUInt32 ( annReader ) if errSymbol != nil { return nil , errors . WithMessage ( errSymbol , " " ) } annotations = append ( annotations , Symbol { id : int32 ( symbol ) } ) } value , errValue := parseNextBinaryValue ( annotations , dataReader ) if errValue != nil { return nil , errors . WithMessage ( errValue , " " ) } if dataReader . Len ( ) > 0 { return nil , errors . Errorf ( " " , numBytes , dataReader . Len ( ) ) } if _ , ok := value . ( padding ) ; ok { return nil , errors . New ( " " ) } return value , nil }
parseBinaryAnnotation reads the annotation and the value that it is
annotating.
parseBinaryAnnotation reads the annotation and the value that it is annotating .
// 0xE as the high byte has two potential uses, one for annotations and one for the // start of the binary version marker.  We are going to be optimistic and assume that // 0xE0 is for the BVM and all other values for the low nibble is for annotations. // We've already verified lengths and are basically performing a copy to // a pre-allocated byte slice.  There is no error to catch. // Since an annotation is a container for a single value there isn't a need to // pre-read the contents so that we know when to stop.