@@ -16,71 +16,47 @@ package storage
1616
1717import (
1818 "context"
19- "encoding/base64"
2019
2120 "github.com/googleapis/gax-go/v2/callctx"
2221)
2322
2423const featureTrackerHeaderName = "x-goog-storage-go-features"
2524
26- // featureCode represents a specific client feature being tracked, represented
27- // as a bit in a bitmask.
28- type featureCode uint8
29-
30- const (
31- featureMultiStream featureCode = 1
32- featurePCU featureCode = 2
33- )
34-
3525// addFeatureAttributes adds the specified feature codes to the context.
3626// Features are stored as a bitmask in the callctx headers and will be
3727// injected into the outgoing request headers by the transport.
38- func addFeatureAttributes (ctx context.Context , features ... featureCode ) context.Context {
28+ func addFeatureAttributes (ctx context.Context , features ... trackedFeature ) context.Context {
3929 if len (features ) == 0 {
4030 return ctx
4131 }
4232
4333 current := getFeatureAttributes (ctx )
4434 updated := current
4535 for _ , f := range features {
46- updated |= uint8 ( f )
36+ updated |= ( 1 << f )
4737 }
4838
4939 if updated == current {
5040 return ctx
5141 }
5242
53- return callctx .SetHeaders (ctx , featureTrackerHeaderName , encodeUint8 ( updated ))
43+ return callctx .SetHeaders (ctx , featureTrackerHeaderName , encodeUint32 ( uint32 ( updated ) ))
5444}
5545
5646// getFeatureAttributes extracts and merges all feature attributes present in the context.
5747// It returns a bitmask represented as a uint8.
58- func getFeatureAttributes (ctx context.Context ) uint8 {
48+ func getFeatureAttributes (ctx context.Context ) uint32 {
5949 ctxHeaders := callctx .HeadersFromContext (ctx )
6050 if vals := ctxHeaders [featureTrackerHeaderName ]; len (vals ) > 0 {
6151 // If multiple values are present in the context (e.g. from nested calls),
6252 // merge them into a single bitmask.
63- var merged uint8
53+ var merged uint32
6454 for _ , v := range vals {
65- if decoded , err := decodeUint8 (v ); err == nil {
55+ if decoded , err := decodeUint32 (v ); err == nil {
6656 merged |= decoded
6757 }
6858 }
6959 return merged
7060 }
7161 return 0
7262}
73-
74- // encodeUint8 encodes a uint8 bitmask into a base64 string for header injection.
75- func encodeUint8 (u uint8 ) string {
76- return base64 .StdEncoding .EncodeToString ([]byte {u })
77- }
78-
79- // decodeUint8 decodes a base64 string back into a uint8 bitmask.
80- func decodeUint8 (s string ) (uint8 , error ) {
81- b , err := base64 .StdEncoding .DecodeString (s )
82- if err != nil || len (b ) < 1 {
83- return 0 , err
84- }
85- return b [0 ], nil
86- }
0 commit comments