genKey creates the key and writes the initial bytes (type byte, length of attribute, and the attribute itself). It leaves the rest of the key empty for further processing if necessary. It also returns next index from where further processing should be done.
(typeByte byte, attr string, extra int)
| 152 | // and the attribute itself). It leaves the rest of the key empty for further processing |
| 153 | // if necessary. It also returns next index from where further processing should be done. |
| 154 | func generateKey(typeByte byte, attr string, extra int) ([]byte, int) { |
| 155 | // Separate namespace and attribute from attr and write namespace in the first 8 bytes of key. |
| 156 | namespace, attr := ParseNamespaceBytes(attr) |
| 157 | prefixLen := 1 + 8 + 2 + len(attr) // byteType + ns + len(pred) + pred |
| 158 | buf := make([]byte, prefixLen+extra) |
| 159 | buf[0] = typeByte |
| 160 | AssertTrue(copy(buf[1:], namespace) == 8) |
| 161 | rest := buf[9:] |
| 162 | |
| 163 | writeAttr(rest, attr) |
| 164 | return buf, prefixLen |
| 165 | } |
| 166 | |
| 167 | // SchemaKey returns schema key for given attribute. Schema keys are stored |
| 168 | // separately with unique prefix, since we need to iterate over all schema keys. |
no test coverage detected