-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_binary.js
48 lines (35 loc) · 1.28 KB
/
create_binary.js
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
// var messages = require('./proto3_test_pb');
var messages = require('./contacts_pb.js');
// Function to save the byte array
var saveByteArray = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, name) {
var blob = new Blob(data, {type: "octet/stream"}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = name;
a.click();
window.URL.revokeObjectURL(url);
};
}());
////////////////////////
var person = new messages.Person();
person.setName("Szabo Marius");
person.setId("1");
person.setEmail("[email protected]");
document.getElementById('ns_name').innerHTML = person.getName();
document.getElementById('ns_id').innerHTML = person.getId();
document.getElementById('ns_email').innerHTML = person.getEmail();
var bytes = person.serializeBinary();
debugger;
console.log('hello');
saveByteArray(bytes, 'contacts.bin');
var desPerson = messages.Person.deserializeBinary(bytes);
var name = desPerson.getName();
var id = desPerson.getId();
var email = desPerson.getEmail();
document.getElementById('ds_name').innerHTML = name;
document.getElementById('ds_id').innerHTML = id;
document.getElementById('ds_email').innerHTML = email;