Questions tagged [protobuf-go]
76 questions
8
votes
1 answer
How to Marshal (using protojson package) array of proto to json in Golang?
How to achieve the following with protojson package in Golang?
Protobuf:
type ProtoResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Xesp isActionResponse_Xesp…

Sukeesh
- 183
- 2
- 10
8
votes
3 answers
Go Protobuf declarations and optional Fields in Go Struct (string pointers)
I am running into a bit of a problem with Protoc and my existing struct that contains nullable string fields.
The struct I am trying to serialize for transmission contains a bunch of fields that are nullable in json (so we can distinguish between…

Tigraine
- 23,358
- 11
- 65
- 110
7
votes
3 answers
Importing proto files from different package causes 'missing method protoreflect'
I am new to Go and Protobufs hence this might be a very noob question. Sorry for that.
I have several packages in my go project and I wanted to create a seperate package which contains all my .proto (also .pb.go) files and then I can import those…

Ahsan Nasir
- 147
- 1
- 2
- 7
5
votes
1 answer
Error module github.com/golang/protobuf is deprecated
I have a problem with the command line go get or go get . in my Golang project. The error is
go: module github.com/golang/protobuf is deprecated: Use the "google.golang.org/protobuf" module instead.
I have tried step by step install package…

Titanio Yudista
- 241
- 4
- 8
5
votes
3 answers
Golang grpc.server: Understanding notions of server, and services
I am trying to understand the notions of Listener, Server and Services in the context of gRPC, Protobuf.
Let's use example on https://grpc.io/docs/languages/go/basics/ as a reference.
Here we have
Listener: lis
gRPC Server: grpcServer :=…

sam
- 777
- 2
- 6
- 19
4
votes
1 answer
Protobuf.Any - Unmarshal from a json.RawMessage
I have data from the DB that is in json.RawMessage format. The specific column is jsonb.
I can't really find a way to unmarshal the data to a property that on proto is defined as protobuf.Any like so.
repeated google.protobuf.Any list = 1;
When I…

Mido
- 73
- 4
4
votes
1 answer
Unknown revision error when implementing Protobuf. (GO)
I am coding at the moment GO with GitHub Repositories and need to pull a package.
go get github.com/cosmos/cosmos-sdk/types
When I enter there comes:
go get: github.com/cosmos/cosmos-sdk@v0.33.2 updating to
github.com/cosmos/cosmos-sdk@v0.44.5…

SurpriseMF
- 174
- 9
4
votes
2 answers
Correctly log protobuf messages as unescaped JSON with zap logger
I have a Go project where I'm using Zap structured logging to log the contents of structs. That's how I initialise the logger:
zapLog, err := zap.NewProductionConfig().Build()
if err != nil {
panic(err)
}
Initially I started with my own structs…

VHristov
- 1,059
- 2
- 13
- 25
4
votes
2 answers
Can't unmarshal bytes using protobuf
I am writing a simple client-server to get to know protobuf.
I have the following message.proto file:
syntax = "proto3";
package main;
message Text {
string name = 1;
int32 id = 2;
}
And this is the code on the client side (ommited…

jasiekc
- 63
- 1
- 6
4
votes
2 answers
Protobuffer API for dynamic Enum Access
I want to know how to set an Enum value dynamically.
I have the following .proto file:
syntax = "proto3";
package garden;
option go_package = "proto/garden";
message Garden {
enum Flower {
Rose = 0;
Acacia = 1;
Firethorn = 2;
…

Konrad
- 107
- 8
3
votes
2 answers
Recursive data structure unmarshalling gives error "cannot parse invalid wire-format data" in Go Lang Protobuf
OS and protobuf version
go1.18.1 linux/amd64, github.com/golang/protobuf v1.5.2
Introduction
I am trying to use recursive proto definitions.
.proto file
message AsyncConsensus {
int32 sender = 1;
int32 receiver = 2;
string unique_id = 3; // to…

Pasindu Tennage
- 1,480
- 3
- 14
- 31
3
votes
1 answer
Service compiling successfully, but message structs not generating - gRPC/Go
I am using gRPC/protobufs as the protocol to communicate between my client and server, both written in go. I'm able to run the command show below to generate the cards.pb.go (server) and cards_grpc.pb.go (client) files without any problem. The…

Sal
- 1,471
- 2
- 15
- 36
3
votes
2 answers
grpc-gateway runtime version conflict
from last few days the protoc generator is generating code with v2 version of github.com/grpc-ecosystem/grpc-gateway. I want to keep using github.com/grpc-ecosystem/grpc-gateway v1.16.0. I am unable to remove the v2 version which is causing…

Jyoti Kumari
- 61
- 5
3
votes
1 answer
MarshalToSizedBuffer for structs undefined when compiling protobuf and attempting to use it in other packages
I'm using gogo/protobuf to generate protobufs for gRPC calls but recently they started failing due a marshalling method not being correctly generated. The error looks like this:
service/v1/service.pb.go:1347:27: m.ListMeta.MarshalToSizedBuffer…

ntalcus
- 31
- 3
2
votes
1 answer
golang protobuf can not unmarshal in a generic type
type Msg[T any] interface {
*T
proto.Message
}
func Handle[T any, U Msg[T]](cb func(req U) (proto.Message, error)) {
msg := new(T)
if err := proto.Unmarshal([]byte{}, msg); err != nil {
}
_, _ = cb(msg)
}
func main() {
…

capsiamese
- 21
- 2