newEncodedFromRoot returns a jsonEncoded from a fully-encoded JSON document.
(v []byte)
| 73 | |
| 74 | // newEncodedFromRoot returns a jsonEncoded from a fully-encoded JSON document. |
| 75 | func newEncodedFromRoot(v []byte) (*jsonEncoded, error) { |
| 76 | v, typ, err := jsonTypeFromRootBuffer(v) |
| 77 | if err != nil { |
| 78 | return nil, err |
| 79 | } |
| 80 | |
| 81 | containerLen := -1 |
| 82 | if typ == ArrayJSONType || typ == ObjectJSONType { |
| 83 | containerHeader, err := getUint32At(v, 0) |
| 84 | if err != nil { |
| 85 | return nil, err |
| 86 | } |
| 87 | containerLen = int(containerHeader & containerHeaderLenMask) |
| 88 | } |
| 89 | |
| 90 | return &jsonEncoded{ |
| 91 | typ: typ, |
| 92 | containerLen: containerLen, |
| 93 | // Manually set the capacity of the new slice to its length, so we properly |
| 94 | // report the memory size of this encoded json object. The original slice |
| 95 | // capacity is very large, since it probably points to the backing byte |
| 96 | // slice of a kv batch. |
| 97 | value: v[:len(v):len(v)], |
| 98 | }, nil |
| 99 | } |
| 100 | |
| 101 | func jsonTypeFromRootBuffer(v []byte) ([]byte, Type, error) { |
| 102 | // Root buffers always have a container header. |
no test coverage detected