-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrpc.go
50 lines (45 loc) · 1010 Bytes
/
grpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"go-voxblox/proto"
"go-voxblox/voxblox"
"log"
)
// MeshServer is used to implement gRPC Server
type MeshServer struct {
proto.UnimplementedMeshServiceServer
meshIntegrator *voxblox.MeshIntegrator
}
// NewMeshServer creates a new MeshServer
func NewMeshServer(meshIntegrator *voxblox.MeshIntegrator) *MeshServer {
return &MeshServer{
meshIntegrator: meshIntegrator,
}
}
// GetMeshBlocks streams the glTF binary data over gRPC
func (s MeshServer) GetMeshBlocks(
in *proto.GetMeshRequest,
srv proto.MeshService_GetMeshBlocksServer,
) error {
s.meshIntegrator.Integrate()
for _, meshBlock := range s.meshIntegrator.MeshLayer.GetBlocks() {
if !meshBlock.HasData() {
continue
}
buf, err := meshBlock.Gltf()
if err != nil {
log.Print(err)
continue
}
err = srv.Send(&proto.GetMeshResult{
Index: fmt.Sprintf(meshBlock.String()),
Bytes: buf.Bytes(),
})
meshBlock.Clear()
if err != nil {
log.Print(err)
return err
}
}
return nil
}