How to extract user_id from response

30 views
Skip to first unread message

Yogeswari Narayasamy

unread,
Aug 21, 2020, 7:28:35 AM8/21/20
to Tinode General
I have the following query result from a grpc call:

&{id:"4" topic:"fnd" sub:<updated_at:1588240740070 acs:<> public:"{"fn":"Yogeswari","pn":"Yoges"}" private:"["mhub:e995b6be-b528-4d1b-9e52-cdcca7ebf4d6"]" user_id:"usr4M22x6F-Fq4" > }

It is returned by res.GetMessage:
    go func() {
       // function to receive a bunch of messages
       for {
           res, err := stream.Recv()
           if err == io.EOF {
               break
           }
           if err != nil {
               log.Fatalf("Error while receiving: %v", err)
               break
           }
           fmt.Printf("Received: %v\n", res.GetMessage())
       }
       close(waitc)
   }()

I understand that the result is of type "isServerMsg_Message"
type isServerMsg_Message interface {
   isServerMsg_Message()
}

So far I've got the following code written which works - wondering if there's a better to make use one of the functions in Tinode to do this extraction. Thank you.

            msg := fmt.Sprintf("%v", res.GetMessage())
           s := strings.Index(msg, "user_id:")
           if s != -1 {
               s += len("user_id:")
               e := strings.Index(msg, " > }")
               if e != -1 {
                   fmt.Printf("pos: %s", msg[s:e])
               }
           }


Gene

unread,
Aug 21, 2020, 12:10:43 PM8/21/20
to Tinode General
Take a look at https://github.com/tinode/chat/blob/master/server/pbconverter.go for how to read and write protobuffer messages in Go.

Gene Sokolov

unread,
Aug 21, 2020, 12:43:46 PM8/21/20
to tin...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Tinode General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tinode+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tinode/31cefd9f-4173-491e-8b5a-7dc5ad746298o%40googlegroups.com.

Yogeswari Narayasamy

unread,
Aug 24, 2020, 6:12:36 AM8/24/20
to Tinode General
Can I make use of these functions in the client code by using "import"? I'm not sure how to do this.

Or alternatively, do I create similar functions to these examples on the client side? If yes, which functions?

Seeking your kind advice on some additional pointers to get started. Thank you.

On Saturday, 22 August 2020 00:43:46 UTC+8, Gene wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to tin...@googlegroups.com.

Gene Sokolov

unread,
Aug 24, 2020, 8:37:04 PM8/24/20
to tin...@googlegroups.com
I really can't guide you at this level. You are asking questions about gRPC. Maybe you should visit the gRPC support forum and ask there.
Alternatively you can ask your company to pay us for support.

To unsubscribe from this group and stop receiving emails from it, send an email to tinode+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tinode/1a56117b-4833-4c3b-8ff1-96c2421e8824o%40googlegroups.com.

yoges nsamy

unread,
Aug 24, 2020, 10:16:08 PM8/24/20
to tin...@googlegroups.com
Opps sorry. Is there a private channel I can reach out to you on to get more info about paid support?

Gene Sokolov

unread,
Aug 24, 2020, 10:29:08 PM8/24/20
to tin...@googlegroups.com
You can reach me at gene @ tinode co

Reply all
Reply to author
Forward
0 new messages