{"modulePath":"github.com/koding/kite","version":"v0.0.0-20180710021347-baa1a54919e3","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package dnode\n\nPackage dnode implements a dnode scrubber. See the following URL for details: [https://github.com/substack/dnode-protocol/blob/master/doc/protocol.markdown](https://github.com/substack/dnode-protocol/blob/master/doc/protocol.markdown)\n\n## Functions\n\n```go\nfunc ParseCallbacks(msg *Message, sender func(id uint64, args []interface{}) error) error\n```\nparseCallbacks parses the message's \"callbacks\" field and prepares callback functions in \"arguments\" field.\n\n## Types\n\n```go\ntype ArgumentError struct {\n\t// contains filtered or unexported fields\n}\n```\nArgumentError is returned when received message contains invalid arguments.\n\n```go\nfunc (e ArgumentError) Error() string\n```\n\n```go\ntype CallbackNotFoundError struct {\n\tID   uint64\n\tArgs *Partial\n}\n```\nCallbackNotFoundError is returned when there is no registered callback for received message.\n\n```go\nfunc (e CallbackNotFoundError) Error() string\n```\n\n```go\ntype CallbackSpec struct {\n\t// Path represents the callback's path in the arguments structure.\n\tPath     Path\n\tFunction Function\n}\n```\nCallbackSpec is a structure encapsulating a Function and it's Path. It is the type of the values in callbacks map.\n\n```go\ntype Function struct {\n\tCaller caller\n}\n```\nFunction is the type for sending and receiving functions in dnode messages.\n\n```go\nfunc Callback(f func(*Partial)) Function\n```\nCallback is the wrapper for function when sending.\n\n```go\nfunc (f Function) Call(args ...interface{}) error\n```\nCall the received function.\n\n```go\nfunc (f Function) IsValid() bool\n```\nIsValid returns true if f represents a Function. It returns false if f is the zero Value.\n\n```go\nfunc (f Function) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (*Function) UnmarshalJSON(data []byte) error\n```\n\n```go\ntype Message struct {\n\t// Method can be an integer or string.\n\tMethod interface{} `json:\"method\"`\n\n\t// Array of arguments\n\tArguments *Partial `json:\"arguments\"`\n\n\t// Integer map of callback paths in arguments\n\tCallbacks map[string]Path `json:\"callbacks\"`\n}\n```\nMessage is the JSON object to call a method at the other side.\n\n```go\ntype MethodNotFoundError struct {\n\tMethod string\n\tArgs   *Partial\n}\n```\nMethodNotFoundError is returned when there is no registered handler for received method.\n\n```go\nfunc (e MethodNotFoundError) Error() string\n```\n\n```go\ntype Partial struct {\n\tRaw           []byte\n\tCallbackSpecs []CallbackSpec\n}\n```\nPartial is the type of \"arguments\" field in dnode.Message.\n\n```go\nfunc (p *Partial) Bool() (b bool, err error)\n```\nBool is a helper to unmarshal a JSON Boolean.\n\n```go\nfunc (p *Partial) Float64() (f float64, err error)\n```\nFloat64 is a helper to unmarshal a JSON Number.\n\n```go\nfunc (p *Partial) Function() (f Function, err error)\n```\nFunction is a helper to unmarshal a callback function.\n\n```go\nfunc (p *Partial) Map() (m map[string]*Partial, err error)\n```\nMap is a helper method to unmarshal to a JSON Object.\n\n```go\nfunc (p *Partial) MarshalJSON() ([]byte, error)\n```\nMarshalJSON returns the raw bytes of the Partial.\n\n```go\nfunc (p *Partial) MustBool() bool\n```\n\n```go\nfunc (p *Partial) MustFloat64() float64\n```\n\n```go\nfunc (p *Partial) MustFunction() Function\n```\n\n```go\nfunc (p *Partial) MustMap() map[string]*Partial\n```\n\n```go\nfunc (p *Partial) MustSlice() []*Partial\n```\n\n```go\nfunc (p *Partial) MustSliceOfLength(length int) []*Partial\n```\n\n```go\nfunc (p *Partial) MustString() string\n```\n\n```go\nfunc (p *Partial) MustUnmarshal(v interface{})\n```\n\n```go\nfunc (p *Partial) One() *Partial\n```\n\n```go\nfunc (p *Partial) Slice() (a []*Partial, err error)\n```\nSlice is a helper method to unmarshal a JSON Array.\n\n```go\nfunc (p *Partial) SliceOfLength(length int) (a []*Partial, err error)\n```\nSliceOfLength is a helper method to unmarshal a JSON Array with specified length.\n\n```go\nfunc (p *Partial) String() (s string, err error)\n```\nString is a helper to unmarshal a JSON String.\n\n```go\nfunc (p *Partial) Unmarshal(v interface{}) error\n```\nUnmarshal unmarshals the raw data (p.Raw) into v and prepares callbacks. v must be a struct that is the type of expected arguments.\n\n```go\nfunc (p *Partial) UnmarshalJSON(data []byte) error\n```\nUnmarshalJSON puts the data into Partial.Raw.\n\n```go\ntype Path []interface{}\n```\nPath represents a callback function's path in the arguments structure. Contains mixture of string and integer values.\n\n```go\ntype Scrubber struct {\n\n\t// Reference to sent callbacks are saved in this map.\n\tsync.Mutex // protects\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewScrubber() *Scrubber\n```\nNew returns a pointer to a new Scrubber.\n\n```go\nfunc (s *Scrubber) GetCallback(id uint64) func(*Partial)\n```\n\n```go\nfunc (s *Scrubber) RemoveCallback(id uint64)\n```\nRemoveCallback removes the callback with id from callbacks. Can be used to remove unused callbacks to free memory.\n\n```go\nfunc (s *Scrubber) Scrub(obj interface{}) (callbacks map[string]Path)\n```\nScrub creates an object that represents \"callbacks\" field in dnode message. The obj argument which will be scrubbed must be of array, slice, struct, or map type. If structure is passed, the returned callbacks map will contain its exported methods of func(\\*Partial) signature. Other functions must be wrapped by Callback function.\n\n```go\nfunc (s *Scrubber) Unscrub(arguments interface{}, callbacks map[string]Path, f func(uint64) functionReceived) error\n```\n\n","path":"github.com/koding/kite/dnode","name":"dnode","synopsis":"Package dnode implements a dnode scrubber.","isRedistributable":true}
