Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

cloudog/sproto-Java

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unfinished yet

sproto-Java

A pure Java implementation of sproto.

Tutorials

You write a Member.sproto file :

  .Person {
    name 0 : string
    id 1 : integer
    email 2 : string

    .PhoneNumber {
        number 0 : string
        type 1 : integer
    }

    phone 3 : *PhoneNumber
}

.AddressBook {
    person 0 : *Person
}

Then you compile it with sprotodump, to produce code in C#.

$ lua sprotodump.lua
usage: lua sprotodump.lua [[<out_option> <out>] ...] <option> <sproto_file ...>

  out_option:
    -d               dump to speciffic dircetory
    -o               dump to speciffic file
    -p               set package name(only cSharp code use)

  option: 
    -cs              dump to cSharp code file
    -spb             dump to binary spb  file
$
$ lua sprotodump.lua -cs Member.sproto  -o Member.cs

Then you use that code like this:

AddressBook address = new AddressBook ();
address.person = new System.Collections.Generic.List<Person> ();

Person person = new Person ();
person.name = "Alice";
person.id = 10000;

person.phone = new System.Collections.Generic.List<Person.PhoneNumber> ();
Person.PhoneNumber num1 = new Person.PhoneNumber ();
num1.number = "123456789";
num1.type = 1;
person.phone.Add (num1);

serialize and deserialize :

byte[] data = address.encode ();                  // encode to bytes

Sproto.SprotoStream stream = new SprotoStream (); // encode to stream
address.encode(stream);

Sproto.SprotoPack spack = new Sproto.SprotoPack ();
byte[] pack_data = spack.pack (data);             // pack
byte[] unpack_data = spack.unpack(pack_data);     // unpack

AddressBook obj = new AddressBook(unpack_data);   // decode

protocol

the Test.sproto file:

Foobar 1 {
  request {
    what 0 : string
  }
  response {
    ok 0 : boolean
  }
}

dump to c# code:

public class Protocol : ProtocolBase {
  public static  Protocol Instance = new Protocol();
  static Protocol() {
    Protocol.SetProtocol<Foobar> (Foobar.Tag);
    Protocol.SetRequest<SprotoType.Foobar.request> (Foobar.Tag);
    Protocol.SetResponse<SprotoType.Foobar.response> (Foobar.Tag);

  }

  public class Foobar {
    public const int Tag = 1;
  }
}

RPC API

Read TestCaseRpc.cs for detail.

Use in Unity

sproto-Unity

benchmark

in my i5-3470 @3.20GHz :

library encode 1M times decode 1M times
sproto-Csharp 2.84s 3.00s
sproto-Csharp(unpack) 1.36s 2.12s
protobuf-net 6.97s 8.09s

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.