/
requests.go
52 lines (41 loc) · 1.17 KB
/
requests.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
51
52
package goscreenmonit
import (
"github.com/micaiahwallace/goscreenmonit/uploadpb"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/known/timestamppb"
)
// Create a client request container with a message
func CreateRequest(reqtype uploadpb.ClientRequest_RequestType, message protoreflect.ProtoMessage) ([]byte, error) {
// Get the request bytes
reqbytes, err := proto.Marshal(message)
if err != nil {
return nil, err
}
// Create a request container
request := &uploadpb.ClientRequest{
Type: reqtype,
Request: reqbytes,
}
// Serialize data
return proto.Marshal(request)
}
// Create a registration message
func CreateRegistration(host, user string) ([]byte, error) {
// Create registration command
regcmd := &uploadpb.Register{
Host: host,
User: user,
}
return CreateRequest(uploadpb.ClientRequest_REGISTER, regcmd)
}
// Create an image upload message
func CreateUpload(images [][]byte) ([]byte, error) {
// create the message
msg := &uploadpb.ImageUpload{
Images: images,
Timestamp: timestamppb.Now(),
}
// Serialize data
return CreateRequest(uploadpb.ClientRequest_UPLOAD, msg)
}