Coder Social home page Coder Social logo

basemax / firstprotobufjs Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 65 KB

A quick and practical look at Protobuf. If you know what is JSON and how its work, you can see how much Proto-Buf is easy.

License: GNU General Public License v3.0

JavaScript 100.00%
js protobuf protof protobuf3 protobufjs protobuf-compiler protobuf-js protobuff protobuf-example javascript

firstprotobufjs's Introduction

First Protobuf (.proto) Javascript

A quick and practical look at Protobuf.

If you know what is JSON and how its work, you can see how much Proto-Buf is easy.

What you dont know you think its hard but when you start to test and working on, you will see its easy.

  • First example implenment using JSON at json.js file,
  • And next same example implenment using Protobuf inside protobuf.js file.

Build proto scheme

$ protoc --js_out=import_style=commonjs,binary:. employees.proto

Compare JSON and Protobuf Data size

[max@workstation grpc-series-protobuf-js]$ ls -al

Size Filename Method
123 employees.json JSON
48 employees.bin Protobuf

Output of examples

[max@workstation grpc-series-protobuf-js]$ node protobuf.js

Ali name is: ALI
Reza name is: REZA
Javad name is: JAVAD
Data: 1001,ALI,50001,1002,REZA,50002,1003,JAVAD,50003
Binary: 10,13,8,233,7,18,3,65,76,73,29,0,81,67,71,10,14,8,234,7,18,4,82,69,90,65,29,0,82,67,71,10,15,8,235,7,18,5,74,65,86,65,68,29,0,83,67,71
Read data from bytes: 1001,ALI,50001,1002,REZA,50002,1003,JAVAD,50003

[max@workstation grpc-series-protobuf-js]$ node json.js

Ali name is: ALI
Reza name is: REZA
Javad name is: JAVAD
Data: [object Object],[object Object],[object Object]
JSON: [{"id":1001,"name":"ALI","salary":50001},{"id":1002,"name":"REZA","salary":50002},{"id":1003,"name":"JAVAD","salary":50003}]
Read data from JSON: [object Object],[object Object],[object Object]

Download protoc

You need to install protoc program on your system, you can download it from https://github.com/protocolbuffers/protobuf/releases depends on your Operation system. whatever your system is Liunx, Windows or OSX.

Next you can run bin/protoc by typing its full path.

For example:

$ /to-the-path/bin/protoc --js_out=import_style=commonjs,binary:. /your-source-path/employees.proto

Setup protoc globally on your system

If you want to install/setup it globally you have to put bin and include directory to your system directory.

You need to copy these directory to the system dir:

  • bin -> /usr/bin/
  • include -> /usr/include/

Maybe, A command to help you:

$ cp -a * /usr/

Go next

If you want to learn protobuf funcitonally deeply, you can check and read the generated file by Protoc at employees_pb.js. c

firstprotobufjs's People

Contributors

dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.