I am not a ruby person, but the project requires ruby. I have a 6 year old
piece of code I am attempting to update. I have recompiled the protobuf
files and protoc decodes a captured input stream correctly; however, the
code no longer works. I wrote a very simple ruby program to show the
issue. The issue is how do I reference the 2nd level of nested protobuf
messages that use proto2 syntax.
My simple code:
*input_stream = STDIN.readsvkmh = TelemetryStream.decode(input_stream)puts
"Device : #{svkmh.system_id}"svkmh_ent = svkmh.enterpriseputs "Level 1 :
#{svkmh_ent}"svkmh_jn = svkmh.enterprise.juniperNetworksputs "Level 2 :
#{svkmh_jn}"*
The output from it:
*Device : Q5Level 1 : <EnterpriseSensors: >../test.rb:17:in
`method_missing': undefined method `juniperNetworks' for
<EnterpriseSensors: >:EnterpriseSensors (NoMethodError) from
../test.rb:17:in `<main>'*
In the origin 6 year old code, this line worked:
*svkmh_jn = svkmh.enterprise.juniperNetworks*
And yet, protoc decodes it correctly:
*$ protoc --decode TelemetryStream telemetry_top.proto < ~/data.gpb | head
-25system_id: "poc-qfx5110-31"component_id: 65535sub_component_id:
0sensor_name: "jti_3_1:/system/:/system/:jsd"sequence_number:
27420timestamp: 1703006625404version_major: 1version_minor: 0enterprise {
[juniperNetworks] { 210 { 151 { 151 {*
The proto file
//
// Copyrights (c) 2015, 2016, Juniper Networks, Inc.
// All rights reserved.
//
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
syntax = "proto2";
import "google/protobuf/descriptor.proto";
extend google.protobuf.FieldOptions {
optional TelemetryFieldOptions telemetry_options = 1024;
}
message TelemetryFieldOptions {
optional bool is_key = 1;
optional bool is_timestamp = 2;
optional bool is_counter = 3;
optional bool is_gauge = 4;
optional bool is_instance = 5;
optional bool is_gauge_min = 6;
optional bool is_gauge_max = 7;
}
message TelemetryStream {
required string system_id = 1 [(telemetry_options).is_key =
true];
optional uint32 component_id = 2 [(telemetry_options).is_key =
true];
optional uint32 sub_component_id = 3 [(telemetry_options).is_key =
true];
optional string sensor_name = 4 [(telemetry_options).is_key =
true];
optional uint32 sequence_number = 5;
optional uint64 timestamp = 6 [(telemetry_options).is_timestamp
= true];
optional uint32 version_major = 7;
optional uint32 version_minor = 8;
optional bool eom = 9;
optional IETFSensors ietf = 100;
optional EnterpriseSensors *enterprise* = 101;
}
message IETFSensors {
extensions 1 to max;
}
message EnterpriseSensors {
extensions 1 to max;
}
extend EnterpriseSensors {
// re-use IANA assigned numbers
optional JuniperNetworksSensors *juniperNetworks* = 2636;
}
message JuniperNetworksSensors {
extensions 1 to max;
}
Thank you for the assistance
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/45f3103d-5610-45fe-a41e-a5f81f7c0059n%40googlegroups.com.