github.com/mavryk-network/mvgo@v1.19.9/micheline/diff.go (about) 1 // Copyright (c) 2020-2021 Blockwatch Data Inc. 2 // Author: alex@blockwatch.cc 3 4 package micheline 5 6 import ( 7 "fmt" 8 ) 9 10 type DiffAction byte 11 12 const ( 13 DiffActionUpdate DiffAction = iota 14 DiffActionRemove 15 DiffActionCopy 16 DiffActionAlloc 17 ) 18 19 func (a DiffAction) String() string { 20 switch a { 21 case DiffActionUpdate: 22 return "update" 23 case DiffActionRemove: 24 return "remove" 25 case DiffActionCopy: 26 return "copy" 27 case DiffActionAlloc: 28 return "alloc" 29 } 30 return "" 31 } 32 33 func (a DiffAction) MarshalText() ([]byte, error) { 34 return []byte(a.String()), nil 35 } 36 37 func (a *DiffAction) UnmarshalText(data []byte) error { 38 ac, err := ParseDiffAction(string(data)) 39 if err != nil && len(data) > 0 { 40 return err 41 } 42 *a = ac 43 return nil 44 } 45 46 func ParseDiffAction(data string) (DiffAction, error) { 47 switch data { 48 case "update": 49 return DiffActionUpdate, nil 50 case "remove": 51 return DiffActionRemove, nil 52 case "copy": 53 return DiffActionCopy, nil 54 case "alloc": 55 return DiffActionAlloc, nil 56 default: 57 return DiffActionUpdate, fmt.Errorf("micheline: invalid big_map_diff action %q", data) 58 } 59 }