MCPcopy Create free account
hub / github.com/DNAProject/DNA / Serialize

Method Serialize

cmd/utils/export.go:57–83  ·  view source on GitHub ↗
(w io.Writer)

Source from the content-addressed store, hash-verified

55}
56
57func (this *ExportBlockMetadata) Serialize(w io.Writer) error {
58 metadata := make([]byte, EXPORT_BLOCK_METADATA_LEN, EXPORT_BLOCK_METADATA_LEN)
59 buf := bytes.NewBuffer(nil)
60 err := serialization.WriteByte(buf, this.Version)
61 if err != nil {
62 return err
63 }
64 err = serialization.WriteByte(buf, this.CompressType)
65 if err != nil {
66 return err
67 }
68 err = serialization.WriteUint32(buf, this.StartBlockHeight)
69 if err != nil {
70 return err
71 }
72 err = serialization.WriteUint32(buf, this.EndBlockHeight)
73 if err != nil {
74 return err
75 }
76 data := buf.Bytes()
77 if len(data) > EXPORT_BLOCK_METADATA_LEN {
78 return fmt.Errorf("metata len size larger than %d", EXPORT_BLOCK_METADATA_LEN)
79 }
80 copy(metadata, data)
81 _, err = w.Write(metadata)
82 return err
83}
84
85func (this *ExportBlockMetadata) Deserialize(r io.Reader) error {
86 metadata := make([]byte, EXPORT_BLOCK_METADATA_LEN, EXPORT_BLOCK_METADATA_LEN)

Callers 1

exportBlocksFunction · 0.95

Calls 5

WriteByteFunction · 0.92
WriteUint32Function · 0.92
ErrorfMethod · 0.80
WriteMethod · 0.80
BytesMethod · 0.45

Tested by

no test coverage detected