function to unmarshal proto message from io reader

Signed-off-by: Michael <michael.lindman@gmail.com>
This commit is contained in:
Michael 2021-08-10 22:30:19 +01:00
parent 8ea9b384f2
commit 0fc2aaee3e
1 changed files with 13 additions and 0 deletions

View File

@ -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
}