latest. linted and building, not working yet

This commit is contained in:
Jeffrey Paul 2022-12-06 18:29:19 +04:00
parent aa3c159521
commit b0c16462c4
2 changed files with 28 additions and 4 deletions

12
mfer/deserialize.go Normal file
View File

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

View File

@ -2,6 +2,7 @@ package mfer
import ( import (
"bytes" "bytes"
"compress/gzip"
"crypto/sha256" "crypto/sha256"
"errors" "errors"
"time" "time"
@ -37,7 +38,7 @@ func (m *manifest) generate() error {
return e return e
} }
} }
dat, err := proto.Marshal(m.pbOuter) dat, err := proto.MarshalOptions{Deterministic: true}.Marshal(m.pbOuter)
if err != nil { if err != nil {
return err return err
} }
@ -54,7 +55,7 @@ func (m *manifest) generateOuter() error {
if m.pbInner == nil { if m.pbInner == nil {
return errors.New("internal error") return errors.New("internal error")
} }
innerData, err := proto.Marshal(m.pbInner) innerData, err := proto.MarshalOptions{Deterministic: true}.Marshal(m.pbInner)
if err != nil { if err != nil {
return err return err
} }
@ -62,9 +63,20 @@ func (m *manifest) generateOuter() error {
h := sha256.New() h := sha256.New()
h.Write(innerData) 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{ o := &MFFileOuter{
// FIXME add more InnerMessage: idc.Bytes(),
InnerMessage: innerData,
Size: int64(len(innerData)), Size: int64(len(innerData)),
Sha256: h.Sum(nil), Sha256: h.Sum(nil),
Version: MFFileOuter_VERSION_ONE, Version: MFFileOuter_VERSION_ONE,