-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support store a value use Namespace and key as index. Signed-off-by: zhengq1 <[email protected]> (cherry picked from commit 5223bd3) Signed-off-by: zhengq1 <[email protected]>
- Loading branch information
Showing
11 changed files
with
262 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package payload | ||
|
||
import ( | ||
"DNA/common/serialization" | ||
"DNA/crypto" | ||
. "DNA/errors" | ||
"errors" | ||
"io" | ||
) | ||
|
||
type StateUpdate struct { | ||
Namespace []byte | ||
Key []byte | ||
Value []byte | ||
Updater *crypto.PubKey | ||
} | ||
|
||
func (su *StateUpdate) Data() []byte { | ||
return []byte{0} | ||
} | ||
|
||
func (su *StateUpdate) Serialize(w io.Writer) error { | ||
err := serialization.WriteVarBytes(w, su.Namespace) | ||
if err != nil { | ||
return NewDetailErr(err, ErrNoCode, "[StateUpdate], Namespace serialize failed.") | ||
} | ||
|
||
err = serialization.WriteVarBytes(w, su.Key) | ||
if err != nil { | ||
return NewDetailErr(err, ErrNoCode, "[StateUpdate], key serialize failed.") | ||
} | ||
|
||
err = serialization.WriteVarBytes(w, su.Value) | ||
if err != nil { | ||
return NewDetailErr(err, ErrNoCode, "[StateUpdate], value serialize failed.") | ||
} | ||
|
||
su.Updater.Serialize(w) | ||
|
||
return nil | ||
} | ||
|
||
func (su *StateUpdate) Deserialize(r io.Reader) error { | ||
var err error | ||
|
||
su.Namespace, err = serialization.ReadVarBytes(r) | ||
if err != nil { | ||
return NewDetailErr(errors.New("[StateUpdate], Namespace deserialize failed."), ErrNoCode, "") | ||
} | ||
|
||
su.Key, err = serialization.ReadVarBytes(r) | ||
if err != nil { | ||
return NewDetailErr(errors.New("[StateUpdate], key deserialize failed."), ErrNoCode, "") | ||
} | ||
|
||
su.Value, err = serialization.ReadVarBytes(r) | ||
if err != nil { | ||
return NewDetailErr(errors.New("[StateUpdate], value deserialize failed."), ErrNoCode, "") | ||
} | ||
|
||
su.Updater = new(crypto.PubKey) | ||
err = su.Updater.DeSerialize(r) | ||
if err != nil { | ||
return NewDetailErr(err, ErrNoCode, "[StateUpdate], updater Deserialize failed.") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.