Created
May 24, 2021 03:20
-
-
Save ksc91u/c219a75d0cef42e34b5b64c5d8aa1546 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
package tutorial; | |
message Person { | |
enum Corpus { | |
UNIVERSAL = 0; | |
WEB = 1; | |
IMAGES = 2; | |
LOCAL = 3; | |
NEWS = 4; | |
PRODUCTS = 5; | |
VIDEO6 = 6; | |
VIDEO7 = 7; | |
VIDEO8 = 8; | |
VIDEO9 = 9; | |
VIDEO10 = 10; | |
VIDEO11 = 11; | |
VIDEO12 = 12; | |
VIDEO13 = 13; | |
VIDEO14 = 14; | |
} | |
Corpus corpus = 1; | |
Corpus corpus2 = 2; | |
Corpus corpus3 = 4; | |
Corpus corpus4 = 5; | |
sfixed64 fix = 3; //Always eight bytes. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val person = | |
PersonOuterClass.Person.newBuilder() | |
.setCorpus(PersonOuterClass.Person.Corpus.NEWS) | |
//.setCorpus2(PersonOuterClass.Person.Corpus.NEWS) | |
//.setCorpus3(PersonOuterClass.Person.Corpus.NEWS) | |
//.setCorpus4(PersonOuterClass.Person.Corpus.NEWS) | |
//.setFix(123) | |
.build() | |
Timber.d( | |
">>> proto byteArray " + person.toByteArray() + ", size " + person.toByteArray | |
().size | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum * 4 + int = 17 | |
enum * 3 + int = 15 | |
enum * 2 + int = 13 | |
enum * 1 + int = 11 | |
enum * 1 = 2 | |
sfixed64 = 8 bytes | |
each new field cost 1 byte | |
enum * 4 + int = 17 (enum 1 byte * 4, sfixed64 8, 5 fields 4 + 8 + 5 = 17) | |
enum * 3 + int = 15 | |
enum * 2 + int = 13 | |
enum * 1 + int = 11 | |
enum * 1 = 2 (enum 1 byte * 1, 1 field 1+1 = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment