var errMissingName … var errMissingColon … var errMissingValue … var errMissingComma … var errMismatchDelim … const errInvalidNamespace … type state … func (s *state) reset() { … } // appendStackPointer appends a JSON Pointer (RFC 6901) to the current value. // The returned pointer is only accurate if s.names is populated, // otherwise it uses the numeric index as the object member name. // // Invariant: Must call s.names.copyQuotedBuffer beforehand. func (s state) appendStackPointer(b []byte) []byte { … } type stateMachine … // reset resets the state machine. // The machine always starts with a minimum depth of 1. func (m *stateMachine) reset() { … } // depth is the current nested depth of JSON objects and arrays. // It is one-indexed (i.e., top-level values have a depth of 1). func (m stateMachine) depth() int { … } // index returns a reference to the ith entry. // It is only valid until the next push method call. func (m *stateMachine) index(i int) *stateEntry { … } // depthLength reports the current nested depth and // the length of the last JSON object or array. func (m stateMachine) depthLength() (int, int) { … } // appendLiteral appends a JSON literal as the next token in the sequence. // If an error is returned, the state is not mutated. func (m *stateMachine) appendLiteral() error { … } // appendString appends a JSON string as the next token in the sequence. // If an error is returned, the state is not mutated. func (m *stateMachine) appendString() error { … } // appendNumber appends a JSON number as the next token in the sequence. // If an error is returned, the state is not mutated. func (m *stateMachine) appendNumber() error { … } // pushObject appends a JSON start object token as next in the sequence. // If an error is returned, the state is not mutated. func (m *stateMachine) pushObject() error { … } // popObject appends a JSON end object token as next in the sequence. // If an error is returned, the state is not mutated. func (m *stateMachine) popObject() error { … } // pushArray appends a JSON start array token as next in the sequence. // If an error is returned, the state is not mutated. func (m *stateMachine) pushArray() error { … } // popArray appends a JSON end array token as next in the sequence. // If an error is returned, the state is not mutated. func (m *stateMachine) popArray() error { … } // needIndent reports whether indent whitespace should be injected. // A zero value means that no whitespace should be injected. // A positive value means '\n', indentPrefix, and (n-1) copies of indentBody // should be appended to the output immediately before the next token. func (m stateMachine) needIndent(next Kind) (n int) { … } // mayAppendDelim appends a colon or comma that may precede the next token. func (m stateMachine) mayAppendDelim(b []byte, next Kind) []byte { … } // needDelim reports whether a colon or comma token should be implicitly emitted // before the next token of the specified kind. // A zero value means no delimiter should be emitted. func (m stateMachine) needDelim(next Kind) (delim byte) { … } // checkDelim reports whether the specified delimiter should be there given // the kind of the next token that appears immediately afterwards. func (m stateMachine) checkDelim(delim byte, next Kind) error { … } // invalidateDisabledNamespaces marks all disabled namespaces as invalid. // // For efficiency, Marshal and Unmarshal may disable namespaces since there are // more efficient ways to track duplicate names. However, if an error occurs, // the namespaces in Encoder or Decoder will be left in an inconsistent state. // Mark the namespaces as invalid so that future method calls on // Encoder or Decoder will return an error. func (m *stateMachine) invalidateDisabledNamespaces() { … } type stateEntry … const stateTypeMask … const stateTypeObject … const stateTypeArray … const stateNamespaceMask … const stateDisableNamespace … const stateInvalidNamespace … const stateCountMask … const stateCountLSBMask … const stateCountOdd … const stateCountEven … // length reports the number of elements in the JSON object or array. // Each name and value in an object entry is treated as a separate element. func (e stateEntry) length() int { … } // isObject reports whether this is a JSON object. func (e stateEntry) isObject() bool { … } // isArray reports whether this is a JSON array. func (e stateEntry) isArray() bool { … } // needObjectName reports whether the next token must be a JSON string, // which is necessary for JSON object names. func (e stateEntry) needObjectName() bool { … } // needImplicitColon reports whether an colon should occur next, // which always occurs after JSON object names. func (e stateEntry) needImplicitColon() bool { … } // needObjectValue reports whether the next token must be a JSON value, // which is necessary after every JSON object name. func (e stateEntry) needObjectValue() bool { … } // needImplicitComma reports whether an comma should occur next, // which always occurs after a value in a JSON object or array // before the next value (or name). func (e stateEntry) needImplicitComma(next Kind) bool { … } // increment increments the number of elements for the current object or array. // This assumes that overflow won't practically be an issue since // 1<<bits.OnesCount(stateCountMask) is sufficiently large. func (e *stateEntry) increment() { … } // decrement decrements the number of elements for the current object or array. // It is the callers responsibility to ensure that e.length > 0. func (e *stateEntry) decrement() { … } // disableNamespace disables the JSON object namespace such that the // Encoder or Decoder no longer updates the namespace. func (e *stateEntry) disableNamespace() { … } // isActiveNamespace reports whether the JSON object namespace is actively // being updated and used for duplicate name checks. func (e stateEntry) isActiveNamespace() bool { … } // invalidateNamespace marks the JSON object namespace as being invalid. func (e *stateEntry) invalidateNamespace() { … } // isValidNamespace reports whether the JSON object namespace is valid. func (e stateEntry) isValidNamespace() bool { … } type objectNameStack … func (ns *objectNameStack) reset() { … } func (ns *objectNameStack) length() int { … } // getUnquoted retrieves the ith unquoted name in the namespace. // It returns an empty string if the last object is empty. // // Invariant: Must call copyQuotedBuffer beforehand. func (ns *objectNameStack) getUnquoted(i int) []byte { … } const invalidOffset … // push descends into a nested JSON object. func (ns *objectNameStack) push() { … } // replaceLastQuotedOffset replaces the last name with the starting offset // to the quoted name in some remote buffer. All offsets provided must be // relative to the same buffer until copyQuotedBuffer is called. func (ns *objectNameStack) replaceLastQuotedOffset(i int) { … } // replaceLastUnquotedName replaces the last name with the provided name. // // Invariant: Must call copyQuotedBuffer beforehand. func (ns *objectNameStack) replaceLastUnquotedName(s string) { … } // clearLast removes any name in the last JSON object. // It is semantically equivalent to ns.push followed by ns.pop. func (ns *objectNameStack) clearLast() { … } // pop ascends out of a nested JSON object. func (ns *objectNameStack) pop() { … } // copyQuotedBuffer copies names from the remote buffer into the local names // buffer so that there are no more offset references into the remote buffer. // This allows the remote buffer to change contents without affecting // the names that this data structure is trying to remember. func (ns *objectNameStack) copyQuotedBuffer(b []byte) { … } func (ns *objectNameStack) ensureCopiedBuffer() { … } type objectNamespaceStack … // reset resets the object namespace stack. func (nss *objectNamespaceStack) reset() { … } // push starts a new namespace for a nested JSON object. func (nss *objectNamespaceStack) push() { … } // last returns a pointer to the last JSON object namespace. func (nss objectNamespaceStack) last() *objectNamespace { … } // pop terminates the namespace for a nested JSON object. func (nss *objectNamespaceStack) pop() { … } type objectNamespace … // reset resets the namespace to be empty. func (ns *objectNamespace) reset() { … } // length reports the number of names in the namespace. func (ns *objectNamespace) length() int { … } // getUnquoted retrieves the ith unquoted name in the namespace. func (ns *objectNamespace) getUnquoted(i int) []byte { … } // lastUnquoted retrieves the last name in the namespace. func (ns *objectNamespace) lastUnquoted() []byte { … } // insertQuoted inserts a name and reports whether it was inserted, // which only occurs if name is not already in the namespace. // The provided name must be a valid JSON string. func (ns *objectNamespace) insertQuoted(name []byte, isVerbatim bool) bool { … } func (ns *objectNamespace) insertUnquoted(name []byte) bool { … } func (ns *objectNamespace) insert(name []byte, quoted bool) bool { … } // removeLast removes the last name in the namespace. func (ns *objectNamespace) removeLast() { … } type uintSet64 … func (s uintSet64) has(i uint) bool { … } func (s *uintSet64) set(i uint) { … } type uintSet … // has reports whether i is in the set. func (s *uintSet) has(i uint) bool { … } // insert inserts i into the set and reports whether it was the first insertion. func (s *uintSet) insert(i uint) bool { … }