Skip to content

Instantly share code, notes, and snippets.

@jyn514
Created July 5, 2019 15:46
Show Gist options
  • Save jyn514/e3ec9028131bc091e9f1d765524561ec to your computer and use it in GitHub Desktop.
Save jyn514/e3ec9028131bc091e9f1d765524561ec to your computer and use it in GitHub Desktop.
Experiments with protobuf decoders

Protobuf Notes

Schema

JSON

Decoded with schema

Decoded with protoc --decode_raw

Decoded with protobuf-inspector from GitHub

Hexdump

message Empty {}

{}

No output.

No output.

root:

empty

The file contained no data.

message Complex {

message Nested {

required int32 an_int = 2;

}

required string a_string = 1;

optional bool an_out_of_order_bool = 9;

optional Nested a_nested_message = 4;

repeated Nested a_repeated_message = 5;

repeated string a_repeated_string = 7;

optional double a_floating_point_field = 10;

}

{

aString: "hi there",

aNestedMessage: { anInt: 123 },

anOutOfOrderBool: true,

aRepeatedMessage: [

{ anInt: 1},

{ anInt: 2},

{ anInt: 4315615}

],

aRepeatedString: [

"string one",

"string two",

"string blah"

],

aFloatingPointField: .123e-1

}

a_string: "hi there"

a_nested_message {

an_int: 123

}

a_repeated_message {

an_int: 1

}

a_repeated_message {

an_int: 2

}

a_repeated_message {

an_int: 4315615

}

a_repeated_string: "string one"

a_repeated_string: "string two"

a_repeated_string: "string blah"

an_out_of_order_bool: true

a_floating_point_field: 0.0123

1: "hi there"

4 {

2: 123

}

5 {

2: 1

}

5 {

2: 2

}

5 {

2: 4315615

}

7: "string one"

7: "string two"

7: "string blah"

9: 1

10: 0x3f8930be0ded288d

root:

1 = "hi there"

4 = message(2 = 123)

5 = message(2 = 1)

5 = message(2 = 2)

5 = message:

2 = 4315615

7 = "string one"

7 = "string two"

7 = "string blah"

9 = 1

10 <64bit> = 0x3F8930BE0DED288D / 4578244089034385549 / 0.012300000

00000000: 0a08 6869 2074 6865 7265 2202 107b 2a02 ..hi there"..{*.

00000010: 1001 2a02 1002 2a05 10df b387 023a 0a73 ...........:.s

00000020: 7472 696e 6720 6f6e 653a 0a73 7472 696e tring one:.strin

00000030: 6720 7477 6f3a 0b73 7472 696e 6720 626c g two:.string bl

00000040: 6168 4801 518d 28ed 0dbe 3089 3f ahH.Q.(...0.?

message FloatingPointFields {

optional float optional_float_field = 1;

required float required_float_field = 2;

repeated float repeated_float_field = 3;

optional float default_float_field = 4 [default = 2.0];

optional double optional_double_field = 5;

required double required_double_field = 6;

repeated double repeated_double_field = 7;

optional double default_double_field = 8 [default = 2.0];

}

{

optionalFloatField: 1,

requiredFloatField: 0,

repeatedFloatField: [

-1,

.1,

-.1,

NaN,

Infinity,

-Infinity,

],

requiredDoubleField: 100000000000,

repeatedDoubleField: [

// largest number that rounds down to zero in IEEE double floating point

0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000247032822920623272088284396434110686182529901307162382212792841250337753635104375932649918180817996189898282347722858865463328355177969898199387398005390939063150356595155702263922908583924491051844359318028499365361525003193704576782492193656236698636584807570015857692699037063119282795585513329278343384093519780155312465972635795746227664652728272200563740064854999770965994704540208281662262378573934507363390079677619305775067401763246736009689513405355374585166611342237666786041621596804619144672918403005300575308490487653917113865916462395249126236538818796362393732804238910186723484976682350898633885879256283027559956575244555072551893136908362547791869486679949683240497058210285131854513962138377228261454376934125320985913276672363281249,

// smallest positive denormalized IEEE double floating point number

0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000247032822920623272088284396434110686182529901307162382212792841250337753635104375932649918180817996189898282347722858865463328355177969898199387398005390939063150356595155702263922908583924491051844359318028499365361525003193704576782492193656236698636584807570015857692699037063119282795585513329278343384093519780155312465972635795746227664652728272200563740064854999770965994704540208281662262378573934507363390079677619305775067401763246736009689513405355374585166611342237666786041621596804619144672918403005300575308490487653917113865916462395249126236538818796362393732804238910186723484976682350898633885879256283027559956575244555072551893136908362547791869486679949683240497058210285131854513962138377228261454376934125320985913276672363281251,

],

defaultDoubleField: 312.01

}

optional_float_field: 1

required_float_field: 0

repeated_float_field: -1

repeated_float_field: 0.1

repeated_float_field: -0.1

repeated_float_field: nan

repeated_float_field: inf

repeated_float_field: -inf

required_double_field: 100000000000

repeated_double_field: 0

repeated_double_field: 4.94065645841247e-324

default_double_field: 312.01

1: 0x3f800000

2: 0x00000000

3: 0xbf800000

3: 0x3dcccccd

3: 0xbdcccccd

3: 0x7fc00000

3: 0x7f800000

3: 0xff800000

6: 0x42374876e8000000

7: 0x0000000000000000

7: 0x0000000000000001

8: 0x40738028f5c28f5c

root:

1 <32bit> = 0x3F800000 / 1065353216 / 1.00000

2 <32bit> = 0x00000000 / 0 / 0.00000

3 <32bit> = 0xBF800000 / -1082130432 / -1.00000

3 <32bit> = 0x3DCCCCCD / 1036831949 / 0.100000

3 <32bit> = 0xBDCCCCCD / -1110651699 / -0.100000

3 <32bit> = 0x7FC00000 / 2143289344 / nan

3 <32bit> = 0x7F800000 / 2139095040 / inf

3 <32bit> = 0xFF800000 / -8388608 / -inf

6 <64bit> = 0x42374876E8000000 / 4771362005757984768 / 1.0000000e+11

7 <64bit> = 0x0000000000000000 / 0 / 0.0000000

7 <64bit> = 0x0000000000000001 / 1 / 4.9406565e-324

8 <64bit> = 0x40738028F5C28F5C / 4644196554159329116 / 312.01000

00000000: 0d00 0080 3f15 0000 0000 1d00 0080 bf1d ....?...........

00000010: cdcc cc3d 1dcd cccc bd1d 0000 c07f 1d00 ...=............

00000020: 0080 7f1d 0000 80ff 3100 0000 e876 4837 ........1....vH7

00000030: 4239 0000 0000 0000 0000 3901 0000 0000 B9........9.....

00000040: 0000 0041 5c8f c2f5 2880 7340 ...A...(.s@

message FixedNum1 {

repeated fixed32 int = 0;

repeated float float = 1;

}

{

int: [0, 1],

float: [0, 1],

}

FixedNum1 { int: [ 0, 1 ], float: [ 0, 1 ] }

NOTE: All other schemas were decoded with protoc. This was decoded with an NPM library because protoc choked on fields with id 0 (see next column).

Failed to parse input.

Found when encoding with protoc:

test.proto:316:26: Field numbers must be positive integers.

root:

0 <32bit> = 0x00000000 / 0 / 0.00000

0 <32bit> = 0x00000001 / 1 / 1.40130e-45

1 <32bit> = 0x00000000 / 0 / 0.00000

1 <32bit> = 0x3F800000 / 1065353216 / 1.00000

00000000: 0500 0000 0005 0100 0000 0d00 0000 000d ................

00000010: 0000 803f ...?

message FixedNum2 { repeated fixed32 int = 2; repeated float float = 1; }

{ int: [0, 1], float: [0, 1], }

float: 0 float: 1 int: 0 int: 1

1: 0x00000000 1: 0x3f800000 2: 0x00000000 2: 0x00000001

1 <32bit> = 0x00000000 / 0 / 0.00000 1 <32bit> = 0x3F800000 / 1065353216 / 1.00000 2 <32bit> = 0x00000000 / 0 / 0.00000 2 <32bit> = 0x00000001 / 1 / 1.40130e-45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment