MCPcopy Index your code
hub / github.com/GJDuck/e9patch / parseBytes

Function parseBytes

src/e9patch/e9json.cpp:936–965  ·  view source on GitHub ↗

* Parse a bytes object. */

Source from the content-addressed store, hash-verified

934 * Parse a bytes object.
935 */
936static Trampoline *parseBytes(Parser &parser)
937{
938 std::vector<uint8_t> bytes;
939
940 expectToken(parser, '[');
941 char token = getToken(parser);
942 while (token != ']')
943 {
944 if (token != TOKEN_NUMBER)
945 unexpectedToken(parser, "bytes entry", token);
946 if (parser.i < 0 || parser.i > UINT8_MAX)
947 parse_error(parser, "failed to parse byte; value (%zd) is "
948 "outside of the byte range (%d..%d)", parser.i, 0, UINT8_MAX);
949 bytes.push_back((uint8_t)parser.i);
950 token = expectToken2(parser, ',', ']');
951 if (token == ',')
952 token = getToken(parser);
953 }
954
955 size_t num_entries = 1;
956 uint8_t *ptr =
957 new uint8_t[sizeof(Trampoline) + num_entries * sizeof(Entry)];
958 Trampoline *T = (Trampoline *)ptr;
959 T->prot = PROT_READ | PROT_EXEC;
960 T->num_entries = num_entries;
961 T->preload = false;
962 T->entries[0] = makeBytesEntry(bytes);
963
964 return T;
965}
966
967/*
968 * Parse instruction metadata.

Callers 1

parseParamsFunction · 0.85

Calls 5

expectTokenFunction · 0.85
getTokenFunction · 0.85
unexpectedTokenFunction · 0.85
expectToken2Function · 0.85
makeBytesEntryFunction · 0.85

Tested by

no test coverage detected