Skip to content

Instantly share code, notes, and snippets.

@alexcpn
Created February 5, 2019 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcpn/e817f029ad3d6f75f8867936cf2cf5bf to your computer and use it in GitHub Desktop.
Save alexcpn/e817f029ad3d6f75f8867936cf2cf5bf to your computer and use it in GitHub Desktop.
Python Protobuffer GRPC assign to nested type and assign to repeated types
obj1 = proto.Object.Detection()
obj1.classname= classname
bbox = proto.BoundingBox()
bbox.X1 =1
# Use CopyFrom to assign to nested element
obj1.boundingbox.CopyFrom(bbox)
obj1.object_id = random.randint(1, 6)
callback = proto.Object()
# use Extend to add to repeated elements
callback.Objects.extend([obj1,])
callback.media_id = int(id)
callback.frame_id = int(id)
message Object {
message Detection {
string classname = 1 ;
BoundingBox boundingbox =2 ;
int32 object_id =5;
}
repeated Detection Objects = 2 ;
double detected_time =3 ;
int32 media_id = 4 ;
int32 frame_id = 5 ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment