Couldn't decode protobuf: #<RuntimeError: Protocol message tag had invalid wire type

Hi,
I am using protobuf logstash plugin for decoding of messages which were encoded using ruby.

Here is my .proto used file

syntax = "proto3";

message SearchRequest {
string query = 1;
int64 page_number = 2;
int64 result_per_page = 3;
}

After compiling of message.proto above using
sudo protoc --ruby_out=. message.proto it gives as

Generated by the protocol buffer compiler. DO NOT EDIT!

source: message.proto

require 'google/protobuf'

Google::Protobuf::DescriptorPool.generated_pool.build do
add_message "SearchRequest" do
optional :query, :string, 1
optional :page_number, :int64, 2
optional :result_per_page, :int64, 3
end
end

SearchRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("SearchRequest").msgclass

And i have written as one ruby script to encode it as

NOTE: You'll need to install the 'google/protobuf' gem

require 'google/protobuf'
require './message_pb.rb'

searchRequest = SearchRequest.new
searchRequest.query = "Hello, How are you?"
searchRequest.page_number = 22222
searchRequest.result_per_page = 111

#searchRequest.to_proto
encoded = SearchRequest.encode(searchRequest)

print encoded

file = File.open("out.bin","w")
file.puts(encoded)

decoded = SearchRequest.decode(encoded)
print "\n\n\n"
print decoded.query
print "\n"
print decoded.page_number
print "\n"
print decoded.result_per_page
print "\n"

And here is my Logstash config file

input
{
file
{
path => "/home/qabuilder/protobuf/out.bin"
start_position => "beginning"
sincedb_path => "/dev/null"

codec => protobuf
{
      class_name => "SearchRequest"
      include_path => ["/home/qabuilder/protobuf/message_pb.rb"]
      protobuf_version => 3
}

}
}

Above works file if i use string parameter as last in message.proto but it wont works if i use it as first parameter gives as error Couldn't decode protobuf: #<RuntimeError: Protocol message tag had invalid wire type.
Why is this happening ?
Does that mean to message.proto should not have string as first parameter.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.