protobuf.js
protobuf.js copied to clipboard
protobuff.encode() does not work as expected
this problem waste my time for 4 days and i don't understand why? protobuff.verify() has no error and all properties set as well
protobuf.js version: ^7.2.3
let settings = {
port_list: {
range: [{
From: 1,
To: 100
}]
},
listen: {},
allocation_strategy: {},
stream_settings: {},
receive_original_destination: {},
sniffing_settings: {
enabled: false
}
}
let error = ReceiverSetting.verify(settings)
let receiverSetting = ReceiverSetting.create(settings)
console.log('error: ', error)
const buffer = ReceiverSetting.encode(receiverSetting).finish();
console.log('receiverSetting:', receiverSetting);
console.log('buffer:', buffer);
const decodedMessage = ReceiverSetting.decode(buffer);
console.log('decodedMessage:', decodedMessage);
and in the log section:
error: null
receiverSetting: ReceiverConfig {
domainOverride: [],
port_list: { range: [ [Object] ] },
listen: {},
allocation_strategy: {},
stream_settings: {},
receive_original_destination: {},
sniffing_settings: {}
}
buffer: <Buffer 12 00>
decodedMessage: ReceiverConfig { domainOverride: [], listen: IPOrDomain {} }
proto file:
syntax = "proto3";
package xray.app.proxyman;
import "common/net/address.proto";
import "common/net/port.proto";
import "transport/internet/config.proto";
import "common/serial/typed_message.proto";
...
...
...
message ReceiverConfig {
xray.common.net.PortList port_list = 1;
xray.common.net.IPOrDomain listen = 2;
AllocationStrategy allocation_strategy = 3;
xray.transport.internet.StreamConfig stream_settings = 4;
bool receive_original_destination = 5;
reserved 6;
repeated KnownProtocols domain_override = 7 [ deprecated = true ];
SniffingConfig sniffing_settings = 8;
}
message SniffingConfig {
// Whether or not to enable content sniffing on an inbound connection.
bool enabled = 1;
// Override target destination if sniff'ed protocol is in the given list.
// Supported values are "http", "tls", "fakedns".
repeated string destination_override = 2;
repeated string domains_excluded = 3;
// Whether should only try to sniff metadata without waiting for client input.
// Can be used to support SMTP like protocol where server send the first
// message.
bool metadata_only = 4;
bool route_only = 5;
}
...
...
...
...
prop_name (snake case) becomes propName (lower camel case)
It is hinted at the first code fragment under Examples section