Skip to content

For testing that protocol buffers properly JSON-encodes (u)int64 as strings in all languages

License

Notifications You must be signed in to change notification settings

summer-ji-eng/intjson

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

int64json

This repo checks that (u)int64s are encoded correctly into JSON. As explained in the Discovery file description and specified in the protobuf documentation these types must be encoded as strings as per the JSON standard.

Instructions

Run cd proto && ./generate.sh to generate the protobuf stubs for your language. Then go to your language directory to run the code.

Results: int encoding

Expectation

  • int32 and uint32 are JSON encoded as numbers, regardless of magnitude
  • int64 and uint64 are JSON encoded as strings, regardless of magnitude

By language

  • Go: PASSED (tested here: go run main.go)
  • Python: PASSED (tested here: python3 main.py)
  • PHP: PASSED (tested separately)
  • Java: PASSED (tested here: mvn compile && mvn exec:java)
  • C#: PASSED (tested here (cd csharp && dotnet build && dotnet ./bin/Debug/netstandard2.0/csharp.dll))
  • Ruby: PASSED (tested here ruby ./ruby/main.rb)

Results: unused enum types

Expectation

protoc generates code for both the top-level and nested enum types, even though neither is used as a field type. The languages tested all seem to do that, as indicated by GENERATED below.

By Language

  • Go: GENERATED
    • string from enum: EndingLetters_OMEGA.String()
    • enum from string: EndingLetters_value["OMEGA"]
  • Java: GENERATED
    • string from enum (ref): EndingLetters.name(EndingLetters.OMEGA)
    • enum from string (ref): EndingLetters.valueOf("OMEGA")
  • C#: GENERATED
  • Python: GENERATED
    • string from enum and enum from string can beaccessed through ProtoPlus
  • Ruby: GENERATED
  • PHP: GENERATED
    • string from enum: name(...)
    • enum from string: value(...)
  • JavaScript: GENERATED

Contributing

  1. Add instructions to proto/generate.sh to generate the proto stubs for your language
  2. Make a top-level directory for your language.
  3. Create a small program that will populate all fields with small and large values. See the go/main.go implementation for an example.
  4. Add the results of your investigation above.
  5. Commit your new source files and the generated proto stubs.

About

For testing that protocol buffers properly JSON-encodes (u)int64 as strings in all languages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 55.1%
  • JavaScript 29.7%
  • Java 5.2%
  • Ruby 4.5%
  • Go 2.4%
  • Python 1.9%
  • Shell 1.2%