package main import ( "bufio" "github.com/gogo/protobuf/proto" protobufCodec "github.com/multiformats/go-multicodec/protobuf" inet "gx/ipfs/QmbD5yKbXahNvoMqzeuNyKQA9vAs9fUvJg2GXeWU1fVqY5/go-libp2p-net" "log" ) // helper method - writes a protobuf go data object to a network stream // data: reference of protobuf go data object to send (not the object itself) // s: network stream to write the data to func sendProtoMessage(data proto.Message, s inet.Stream) bool { writer := bufio.NewWriter(s) enc := protobufCodec.Multicodec(nil).Encoder(writer) err := enc.Encode(data) if err != nil { log.Println(err) return false } writer.Flush() return true }