-
Notifications
You must be signed in to change notification settings - Fork 0
/
serialization.go
46 lines (38 loc) · 1.37 KB
/
serialization.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
package main
import (
"github.com/3cb/seattle911/seattle"
flatbuffers "github.com/google/flatbuffers/go"
)
func serialize(fireCalls []FireCall, date string) []byte {
builder := flatbuffers.NewBuilder(1024)
fire := []flatbuffers.UOffsetT{}
for _, call := range fireCalls {
address := builder.CreateString(call.Address)
datetime := builder.CreateString(call.DateTime)
incidentNumber := builder.CreateString(call.IncidentNumber)
latitude := builder.CreateString(call.Latitude)
longitude := builder.CreateString(call.Longitude)
tp := builder.CreateString(call.Type)
seattle.FireCallStart(builder)
seattle.FireCallAddAddress(builder, address)
seattle.FireCallAddDatetime(builder, datetime)
seattle.FireCallAddIncidentNumber(builder, incidentNumber)
seattle.FireCallAddLatitude(builder, latitude)
seattle.FireCallAddLongitude(builder, longitude)
seattle.FireCallAddType(builder, tp)
fire = append(fire, seattle.FireCallEnd(builder))
}
seattle.MessageStartFireCallsVector(builder, len(fireCalls))
for i := len(fire) - 1; i >= 0; i-- {
builder.PrependUOffsetT(fire[i])
}
fCalls := builder.EndVector(len(fireCalls))
d := builder.CreateString(date)
seattle.MessageStart(builder)
seattle.MessageAddDate(builder, d)
seattle.MessageAddFireCalls(builder, fCalls)
msg := seattle.MessageEnd(builder)
builder.Finish(msg)
buf := builder.FinishedBytes()
return buf
}