I'm trying to import a message defined in one .proto (ndarray.proto
) file into another (image.proto
). My folder structure is:
proto/
|
|-- image.proto
|
|-- numproto/
| |
| |-- protobuf
| |
| |-- ndarray_pb2.py
| |-- ndarray.proto
and inside of image.proto
I have:
syntax = "proto3";
package Image;
import "numproto/protobuf/ndarray.proto";
message image {
int32 width = 1;
int32 height = 2;
numproto.protobuf.NDArray image_data = 3;
}
I would expect that I could now assign an NDArray to image_data, but when I try the following in a Python script:
import image_pb2
from numproto import ndarray_to_proto, proto_to_ndarray
image = image_pb2.image()
a = np.hstack((np.ones(10), np.zeros(10)))
data = ndarray_to_proto(a)
image.image_data = data
I get an error:
TypeError: Couldn't build proto file into descriptor pool!
Invalid proto descriptor for file "image.proto":
numproto/protobuf/ndarray.proto: Import "numproto/protobuf/ndarray.proto" has not been loaded.
Image.image.image_data: "numproto.protobuf.NDArray" seems to be defined in "ndarray.proto", which is not imported by "image.proto". To use it here, please add the necessary import.
Am I incorrectly importing the ndarray.proto
file into image.proto
?