my question is do you have a procedure to decode protobuf on client side.

On Tuesday, January 16, 2018 at 11:33:08 AM UTC-6, Bo Yang wrote:
>
> Sorry, protobuf.js is not maintained by us. Please contact the owner.
>
> On Tue, Jan 16, 2018 at 9:21 AM <[email protected] <javascript:>> 
> wrote:
>
>> protobuf.js version: 6.8.4
>>
>> I am using Django-channels in the backed and javascript WebSockets on the 
>> front end. I have a set of 10 .proto files which import one or more of 
>> these .proto files. I was able to serialize my JSON on the server side, 
>> send data over the wire and receive base64 encoded message. I am having 
>> difficulty trying to convert this message to JSON.
>>
>> I have encountered following problems.
>>
>>    - if I convert my actual data to the uint8array buffer and pass it 
>>    into decode: illegal buffer
>>    - if i use toObject() prints completely wrong object. the structure 
>>    of obj is correct but the values that go into this template are erratic.
>>
>> ------------------------------
>>
>> -------protobuf.load("/static/proto/web.proto",function(err,root){
>>
>> wssm = root.lookupType("web.WebSocketServerMessage");
>> var obj1 = wssm.toObject(atob(message.data), {
>>     enums: String,  // enums as string names
>>     longs: String,  // longs as strings (requires long.js)
>>     bytes: String,  // bytes as base64 encoded strings
>>     defaults: true, // includes default values
>>     arrays: true,   // populates empty arrays (repeated fields) even if 
>> defaults=false
>>     objects: true,  // populates empty objects (map fields) even if 
>> defaults=false
>>     oneofs: true    // includes virtual oneof fields set to the present 
>> field's name
>> });
>>
>> ------------------------------
>>
>> -------
>> Object { type: "REPLY", reply: null, exception: null, data: null } 
>> ##COMMENTS: type is wrong, expected to have values in reply and data.
>>
>>
>> it will be helpful if you could point me to a snippet.
>> Note: I am not using node, need help only in js client.
>>
>> my message on client looks like :
>> [image: image]
>>
>>
>>
>>
>> CODE:::
>>
>> i have tried out what you have suggested it dosent work . please look at 
>> the program and commented output.
>>
>> `var wssm=null
>> protobuf.load("/static/proto/web.proto",function(err,root){
>>
>> console.log(err);
>> wssm = root.lookupType("web.WebSocketServerMessage");
>>
>> socket.onmessage = function (message2){
>>
>> console.log("BASE64 encoded : ",message2.data);
>>
>> /*00:07:56.460 BASE64 encoded : 
>> CAQilwEIBxAIGpABCo0BChkKFy9DRlMvQ0ZFX0VWUy9DbWRDb3VudGVyEgQIAigAGgQIAigAIJeRr+KPLCivyprrnAkwADgBWhcyMDE4LTAxLTE2VDAwOjA3OjU2LjE3NWIXMTk4MC0wMS0xN1QxNzozNzoyOS44NDe4AfOcr+KPLMIBFzIwMTgtMDEtMTZUMDA6MDc6NTcuNjc1
>>  
>> 1 client2.js:294:17*/
>>
>> console.log("applied atob() : ",atob(message2.data));
>>
>> /
>>
>>
>> *00:07:56.462 applied atob() : 
>> ��"�������������/CFS/CFE_EVS/ErrCounter����(*/
>>
>> console.log("protobuf.util.base64 : 
>> ",protobuf.util.base64.decode(message2.data));
>>
>> /*TypeError: buffer is undefined[Learn More] protobuf.js:204:17
>> decode 
>> http://cdn.rawgit.com/dcodeIO/protobuf.js/6.8.4/dist/protobuf.js:204:17
>> Session_Maintainance.prototype.subscribeTelemetry/</socket.onmessage 
>> http://127.0.0.1:8000/client2.js:296:57*/
>>
>> });`
>>
>> :::
>>
>>
>>
>> # web.proto
>> syntax="proto2";
>>
>> package web;
>> option java_package = "org.yamcs.protobuf";
>>
>> import "yamcs.proto";
>> import "archive.proto";
>> import "commanding.proto";
>> import "pvalue.proto";
>> import "alarms.proto";
>> import "yamcsManagement.proto";
>>
>> message WebSocketClientMessage {
>> optional uint32 protocolVersion = 1;
>> optional uint32 sequenceNumber = 2;
>> optional string resource = 3;
>> optional string operation = 4;
>> optional bytes data = 5;
>> }
>>
>> message WebSocketServerMessage {
>> enum MessageType {
>> REPLY = 2; // one-time rpc-style ACK reply
>> EXCEPTION = 3; // one-time rpc-style exception reply
>> DATA = 4; // various subscribed data
>> }
>>
>> message WebSocketReplyData {
>> optional uint32 protocolVersion = 1;
>> optional int32 sequenceNumber = 2; // allow for -1
>> optional string type = 3;
>> optional string message = 4;
>> optional bytes data = 5; // Structured data
>> }
>>
>> message WebSocketExceptionData {
>> optional uint32 protocolVersion = 1;
>> optional int32 sequenceNumber = 2; // allow for -1
>> optional string type = 3;
>> optional string message = 4;
>> optional bytes data = 5; // Structured exception data
>> }
>>
>> // Could use protobuf3 Any-type some day.
>> message WebSocketSubscriptionData {
>> optional uint32 sequenceNumber = 1;
>> optional yamcs.ProtoDataType type = 2;
>> optional pvalue.ParameterData parameterData = 3;
>> optional commanding.CommandHistoryEntry command = 4;
>> optional yamcsManagement.ProcessorInfo processorInfo = 5;
>> optional yamcsManagement.ClientInfo clientInfo = 6;
>> optional yamcsManagement.Statistics statistics = 7;
>> optional yamcs.Event event = 8;
>> optional archive.StreamData streamData = 9;
>> optional alarms.AlarmData alarmData = 10;
>> optional yamcs.TimeInfo timeInfo = 11;
>> optional yamcsManagement.LinkEvent linkEvent = 12;
>> optional commanding.CommandQueueInfo commandQueueInfo = 13;
>> optional commanding.CommandQueueEvent commandQueueEvent = 14;
>> optional yamcs.TmPacketData tmPacket = 15;
>> optional ConnectionInfo connectionInfo = 16;
>>
>> optional WebSocketExtensionData extensionData = 100;
>>
>> }
>>
>> optional MessageType type = 1;
>> optional WebSocketReplyData reply = 2;
>> optional WebSocketExceptionData exception = 3;
>> optional WebSocketSubscriptionData data = 4;
>> }
>>
>> // Escape hatch for providing non-core Yamcs data over web socket
>> message WebSocketExtensionData {
>> optional uint32 type = 1;
>> optional bytes data = 2;
>> }
>>
>> // Generic holder for an exception
>> message RestExceptionMessage {
>> optional string type = 1;
>> optional string msg = 2;
>> extensions 100 to 200;
>> }
>>
>> message ParameterSubscriptionRequest {
>> repeated yamcs.NamedObjectId id = 1;
>> //if set to true, an error message will be sent back if any parameter 
>> from the list above is invalid
>> // by default is false
>> optional bool abortOnInvalid = 2;
>>
>> // if set to true, send parameter updates when parameters expire.
>> // the parameter will have the same value and timestamp like the previous 
>> sent one, but the acquisition status will be set to EXPIRED (instead of 
>> ACQUIRED)
>> //by default is false
>> optional bool updateOnExpiration = 3;
>>
>> //if set to true (default), send a first batch of the parameters from 
>> cache if available
>> // otherwise just wait for the parameters to be updated
>> optional bool sendFromCache = 4;
>>
>> //Hack to allow the old subscribe with NamedObjectList to work when json 
>> is used.
>> // When protobuf is used, the "id" will work since it uses the same field 
>> id (1) with the "list" from NamedObjectList
>> // remove this field when we are sure nobody uses the old method
>> repeated yamcs.NamedObjectId list = 10000 [deprecated=true];
>> }
>>
>> message ParameterSubscriptionResponse {
>> repeated yamcs.NamedObjectId valid = 1;
>> repeated yamcs.NamedObjectId invalid = 2;
>> }
>>
>> //sent via the websocket with information about connected client
>> message ConnectionInfo {
>> optional int32 clientId = 1;
>> optional yamcsManagement.YamcsInstance instance = 2;
>> optional yamcsManagement.ProcessorInfo processor = 3;
>> }
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/protobuf.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to