DecodeValueTag decodes a value encoded by EncodeValueTag, used as a prefix in each of the other EncodeFooValue methods. The tag is structured such that the encoded column id can be dropped from the front by removing the first `typeOffset` bytes. DecodeValueTag, PeekValueLength and each of the Decod
(b []byte)
| 2034 | // will return the same thing. PeekValueLength works as expected with either of |
| 2035 | // `b` or `b[typeOffset:]`. |
| 2036 | func DecodeValueTag(b []byte) (typeOffset int, dataOffset int, colID uint32, typ Type, err error) { |
| 2037 | // TODO(dan): This can be made faster by special casing the single byte |
| 2038 | // version and skipping the column id extraction when it's not needed. |
| 2039 | if len(b) == 0 { |
| 2040 | return 0, 0, 0, Unknown, fmt.Errorf("empty array") |
| 2041 | } |
| 2042 | var n int |
| 2043 | var tag uint64 |
| 2044 | b, n, tag, err = DecodeNonsortingUvarint(b) |
| 2045 | if err != nil { |
| 2046 | return 0, 0, 0, Unknown, err |
| 2047 | } |
| 2048 | colID = uint32(tag >> 4) |
| 2049 | |
| 2050 | typ = Type(tag & 0xf) |
| 2051 | typeOffset = n - 1 |
| 2052 | dataOffset = n |
| 2053 | if typ == SentinelType { |
| 2054 | _, n, tag, err = DecodeNonsortingUvarint(b) |
| 2055 | if err != nil { |
| 2056 | return 0, 0, 0, Unknown, err |
| 2057 | } |
| 2058 | typ = Type(tag) |
| 2059 | dataOffset += n |
| 2060 | } |
| 2061 | return typeOffset, dataOffset, colID, typ, nil |
| 2062 | } |
| 2063 | |
| 2064 | // DecodeBoolValue decodes a value encoded by EncodeBoolValue. |
| 2065 | func DecodeBoolValue(buf []byte) (remaining []byte, b bool, err error) { |
no test coverage detected
searching dependent graphs…