Add a generic message reader interface - #363
Conversation
| // | ||
| // Implementations may use the provided message to store the | ||
| // unmarshalled message. | ||
| ReadMessage(ctx context.Context, d digest.Digest, msg T) (T, error) |
There was a problem hiding this comment.
What's with the msg T argument? Normally you only provide that to ToProto() to indicate the type you're interested in. For MessageReader that should already be implied by the interface itself.
There was a problem hiding this comment.
msg T argument removed in favor of adding an allocator to the constructor.
Adds a generic message reader interface for reading proto messages from storage. Many Buildbarn components depend on blobstore.BlobAccess only as a source of proto.Message and this interface allows us to sever that dependency in components which are otherwise not interested in the blobstore.BlobAccess interface.
5eb0772 to
32125a7
Compare
|
State of latest version:
Looking at places which reads messages from the CAS in bb-storage, there only seems to be In the last commit here
With: Which allows me to tie up the loop. Does this look like a good signature and if so I can consume the |
| "google.golang.org/protobuf/proto" | ||
| ) | ||
|
|
||
| type blobAccessMessageReader[T proto.Message] struct { |
There was a problem hiding this comment.
If you change this line to:
type blobAccessMessageReader[T any, TPtr interface {
*T
proto.Message
}] struct {Then you can use T to refer to a concrete message type, and TPtr whenever you need a pointer to one. That way you can get rid of the allocator function.
|
|
||
| // MessageReader can be used to read a parsed proto.Message from the | ||
| // Content Addressable Storage. | ||
| type MessageReader[T proto.Message] interface { |
There was a problem hiding this comment.
If you wanted to, you could change this proto.Message to any. That way you get rid of the dependency on the Protobuf package. Though in this case I'm ambivalent.
|
|
||
| // BlobStreamReader provides a stream to the raw bytes of a blob. | ||
| type BlobStreamReader interface { | ||
| ReadStream(ctx context.Context, d digest.Digest) (io.ReadCloser, error) |
There was a problem hiding this comment.
I'm just thinking: aren't we going to need an interface like this on the NaiveBuildDirectory side to download files? If so, maybe this should also live in pkg/cas?
Adds a generic message reader interface for reading proto messages from storage. Many Buildbarn components depend on blobstore.BlobAccess only as a source of proto.Message and this interface allows us to sever that dependency in components which are otherwise not interested in the blobstore.BlobAccess interface.