MCPcopy Create free account
hub / github.com/devld/go-drive / setData

Method setData

drive/script/index.go:52–68  ·  view source on GitHub ↗
(vm *s.VM, args s.Values)

Source from the content-addressed store, hash-verified

50}
51
52func (sd *ScriptDrive) setData(vm *s.VM, args s.Values) any {
53 data := args.Get(0)
54 keys := data.Keys()
55 encodedValues := make(map[string]json.RawMessage, len(keys))
56 for _, k := range keys {
57 encoded, e := vm.EncodeJSONValue(data.Get(k))
58 if e != nil {
59 vm.ThrowTypeError("shared state must be JSON serializable: " + e.Error())
60 }
61 encodedValues[k] = encoded
62 }
63
64 sd.mu.Lock()
65 defer sd.mu.Unlock()
66 maps.Copy(sd.data, encodedValues)
67 return nil
68}
69
70func (sd *ScriptDrive) getData(vm *s.VM, args s.Values) any {
71 key := args.Get(0).String()

Callers 1

addEntryIntoDataTransferFunction · 0.80

Calls 8

KeysMethod · 0.80
EncodeJSONValueMethod · 0.80
ThrowTypeErrorMethod · 0.80
GetMethod · 0.65
ErrorMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65
CopyMethod · 0.65

Tested by

no test coverage detected