Skip to content

Commit

Permalink
query sub/bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumer committed May 3, 2024
1 parent be72267 commit c7b3088
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/decoders.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export const getValue = (field, type) => {
return field.value
}

if (type === 'sub') {
return new RawProto(field.value).readMessage()
}

if (type === 'string') {
return string(field.value)
}
Expand Down
18 changes: 18 additions & 0 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,21 @@ test('Packed Repeated Fields', () => {
const tree = new RawProto([0x32, 0x06, 0x03, 0x8e, 0x02, 0x9e, 0xa7, 0x05]).readMessage()
expect(query(tree, '6:packedvarint')).toEqual([[3, 270, 86942]])
})

// Here are some other type-tests

test('Submessage as bytes', () => {
/*
3: {1: 150}
*/
const tree = new RawProto([0x1a, 0x03, 0x08, 0x96, 0x01]).readMessage()
expect(query(tree, '3:bytes')).toEqual([new Uint8Array([8, 150, 1])])
})

test('Submessage as sub', () => {
/*
3: {1: 150}
*/
const tree = new RawProto([0x1a, 0x03, 0x08, 0x96, 0x01]).readMessage()
expect(query(tree, '3:sub')).toEqual([[{ index: 1, path: '1', pos: [1, 3], renderType: 'int', value: 150, type: 0 }]])
})

0 comments on commit c7b3088

Please sign in to comment.