function to unmarshal proto message from io reader
Signed-off-by: Michael <michael.lindman@gmail.com>
This commit is contained in:
parent
8ea9b384f2
commit
0fc2aaee3e
13
pb/proto.go
13
pb/proto.go
|
@ -2,6 +2,7 @@ package pb
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
|
@ -50,3 +51,15 @@ func SendFile(url string, headers map[string]string, message protoreflect.ProtoM
|
|||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// UnmarshalReader unmarshals io reader into proto message
|
||||
func UnmarshalReader(r io.Reader, m protoreflect.ProtoMessage) error {
|
||||
body, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := proto.Unmarshal(body, m); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Reference in New Issue