--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.
// FlatbuffersCodec is a Codec implementation with flatbuffers.
type FlatbuffersCodec struct {
}
func (FlatbuffersCodec) Marshal(v interface{}) ([]byte, error) {
fb := v.(flatbuffers.Message)
return fb.Table().Bytes, nil
}
func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error {
fb := v.(flatbuffers.Message)
flatbuffers.GetRootAs(data, 0, fb)
fb.SetTable(fb.Table())
return nil
}
func (FlatbuffersCodec) String() string {
return "flatbuffers"
}type Message interface {
Table() Table
SetTable(Table)
Init(buf []byte, i UOffsetT)
}// Implement the table accessors
static void GenTableAccessors(const StructDef &struct_def,
std::string *code_ptr) {
std::string &code = *code_ptr;
GenReceiver(struct_def, code_ptr);
code += " Table() flatbuffers.Table ";
code += "{\n";
code += "\treturn rcv._tab\n";
code += "}\n\n";
GenReceiver(struct_def, code_ptr);
code += " SetTable(table flatbuffers.Table) ";
code += "{\n";
code += "\trcv._tab = table\n";
code += "}\n\n";
}func GetRootAs(buf []byte, offset UOffsetT, v Message) {
n := GetUOffsetT(buf[offset:])
v.Init(buf, n+offset)
}opts = append(opts, grpc.WithCodec(grpc.FlatbuffersCodec{}))opts = append(opts, grpc.CustomCodec(grpc.FlatbuffersCodec{}))
| // 1. make the flatbuffers builder | |
| flatbuffers::FlatBufferBuilder builder; | |
| // 2. create the payload | |
| // ignore the return type for now | |
| auto req = smf_gen::fbs::rpc::CreateRequest( | |
| builder, builder.CreateString("hello from client")); | |
| builder.Finish(req); | |
| smf::LOG_INFO("About to send rpc request to server of size: {}", | |
| builder.GetSize()); | |
| smf::rpc_envelope e(builder.GetBufferPointer(), builder.GetSize()); | |
| client.GetSend(std::move(e)) | |
| .then([](auto reply) { | |
| if(reply) { | |
| smf::LOG_INFO("Got reply from server with status: ", | |
| reply.ctx->status()); | |
| smf::LOG_INFO("Got reply from server with response name: ", | |
| *reply.get()->mutable_name()->c_str()); | |
| } else { | |
| smf::LOG_INFO("Well.... the server had an OoOps!"); | |
| } |
Gonzalo: that seems a problematic path to me. Proto -> fbs is only an approximate conversion, and having to modify generated code is not workable.
The better way to support Go (or any other language) with GRPC would be to do what the C++ implementation did, which is two steps:
- Refactor the GRPC code generator for Go to not depend on protobuf analogous to what I did for C++: https://github.com/grpc/grpc/pull/6130
- Write a Go code generator similar to: https://github.com/google/flatbuffers/commit/48f37f9e0a04f2b60046dda7fef20a8b0ebc1a70
--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
Thanks, that looks pretty cool.As for the schema, I think more of the definition of this should be left to FlatBuffers itself.With `dynamic_headers: [DynamicHeader];` you are emulating a HTTP style header. But FlatBuffers itself already has optional fields and such, so those are best of being defined directly in a schema. Besides, strings for keys and values take up a LOT of space, whereas a scalar FlatBuffer field can be tiny.
Also don't see the point of defining Header, since apparently it is outside the FlatBuffer data.
Again, please look at the FlatBuffers <-> GRPC integration in C++, it works entirely without any use of Protobuf or its classes.
--
You received this message because you are subscribed to a topic in the Google Groups "FlatBuffers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/flatbuffers/sxuOVG0nnJ4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to flatbuffers...@googlegroups.com.