#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "Client.pb-c.h"
#include "Cell.pb-c.h"
#include "Comparator.pb-c.h"
#include "Filter.pb-c.h"
#include "HBase.pb-c.h"
#include "MapReduce.pb-c.h"
// get 'stu2','rk01'
char packet_bytes[] = {
/*0x00, 0x00, 0x00, 0x66, 0x0f,*/ 0x08, 0x04, 0x1a,
0x03, 0x47, 0x65, 0x74, 0x20, 0x01, 0x30, 0x00,
0x38, 0xe0, 0xd4, 0x03, 0x55, 0x0a, 0x39, 0x08,
0x01, 0x12, 0x35, 0x73, 0x74, 0x75, 0x32, 0x2c,
0x2c, 0x31, 0x35, 0x37, 0x39, 0x30, 0x37, 0x31,
0x33, 0x35, 0x35, 0x38, 0x34, 0x38, 0x2e, 0x38,
0x34, 0x61, 0x33, 0x65, 0x39, 0x38, 0x63, 0x65,
0x63, 0x30, 0x32, 0x39, 0x39, 0x65, 0x64, 0x35,
0x66, 0x30, 0x61, 0x33, 0x66, 0x39, 0x61, 0x63,
0x34, 0x66, 0x35, 0x39, 0x62, 0x38, 0x37, 0x2e,
0x12, 0x18, 0x0a, 0x04, 0x72, 0x6b, 0x30, 0x32,
0x2a, 0x0c, 0x08, 0x00, 0x10, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x30, 0x01,
0x38, 0x01
};
//Hbase__Pb__GetRequest Hbase__Pb__GetRequest * hbase__pb__get_request__unpack
//void hbase__pb__get_request__free_unpacked
int main()
{
int buf_len;
Hbase__Pb__GetRequest *message; // or Hbase__Pb__Get *message; ->result is unpacked failed
buf_len = sizeof(packet_bytes);
if ((message = hbase__pb__get_request__unpack(NULL, buf_len, packet_bytes)) == NULL)
{
printf("unpacked failed , buf_len = %d\n", buf_len);
goto err;
}
hbase__pb__get_request__free_unpacked(message, NULL);
return 0;
err:
free(buf);
return -1;
}
Когда я запускаю его, я получаю:
echo -e -n "\x08\x04\x1a\x03\x47\x65\x74\x20\x01\x30\x00\x38\xe0\xd4\x03\x55\x0a\x39\x08\x01\x12\x35\x73\x74\x75\x32\x2c\x2c\x31\x35\x37\x39\x30\x37\x31\x33\x35\x35\x38\x34\x38\x2e\x38\x34\x61\x33\x65\x39\x38\x63\x65\x63\x30\x32\x39\x39\x65\x64\x35\x66\x30\x61\x33\x66\x39\x61\x63\x34\x66\x35\x39\x62\x38\x37\x2e\x12\x18\x0a\x04\x72\x6b\x30\x32\x2a\x0c\x08\x00\x10\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x30\x01\x38\x01" |protoc --decode_raw
1: 4
3: "Get"
4: 1
6: 0
7: 60000
10: 0x0108390a
2: "stu2,,1579071355848.84a3e98cec0299ed5f0a3f9ac4f59b87."
2 {
1: "rk02"
5 {
1: 0
2: 9223372036854775807
}
6: 1
7: 1
}
Файл * .proto находится здесь https://github.com/apache/hbase/tree/master/hbase-protocol/src/main/protobuf; Полезная нагрузка имеет 106 байтов, первые 4 байта - это длина остальных байтов. Я понятия не имею, какие данные можно использовать для десериализации. Я не на том пути?