latest. linted and building, not working yet
This commit is contained in:
parent
aa3c159521
commit
b0c16462c4
|
@ -0,0 +1,12 @@
|
|||
package mfer
|
||||
|
||||
import "google.golang.org/protobuf/proto"
|
||||
|
||||
func NewFromProto(input []byte) (*manifest, error) {
|
||||
m := New()
|
||||
err := proto.Unmarshal(input, m.pbOuter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
|
@ -2,6 +2,7 @@ package mfer
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"time"
|
||||
|
@ -37,7 +38,7 @@ func (m *manifest) generate() error {
|
|||
return e
|
||||
}
|
||||
}
|
||||
dat, err := proto.Marshal(m.pbOuter)
|
||||
dat, err := proto.MarshalOptions{Deterministic: true}.Marshal(m.pbOuter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -54,7 +55,7 @@ func (m *manifest) generateOuter() error {
|
|||
if m.pbInner == nil {
|
||||
return errors.New("internal error")
|
||||
}
|
||||
innerData, err := proto.Marshal(m.pbInner)
|
||||
innerData, err := proto.MarshalOptions{Deterministic: true}.Marshal(m.pbInner)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -62,9 +63,20 @@ func (m *manifest) generateOuter() error {
|
|||
h := sha256.New()
|
||||
h.Write(innerData)
|
||||
|
||||
idc := new(bytes.Buffer)
|
||||
gzw, err := gzip.NewWriterLevel(idc, gzip.BestCompression)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = gzw.Write(innerData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gzw.Close()
|
||||
|
||||
o := &MFFileOuter{
|
||||
// FIXME add more
|
||||
InnerMessage: innerData,
|
||||
InnerMessage: idc.Bytes(),
|
||||
Size: int64(len(innerData)),
|
||||
Sha256: h.Sum(nil),
|
||||
Version: MFFileOuter_VERSION_ONE,
|
||||
|
|
Loading…
Reference in New Issue