Add basic protobuf message parsing

This commit is contained in:
2024-06-23 15:12:15 +09:30
parent 9c2531a034
commit d484f75540
3 changed files with 105 additions and 41 deletions

View File

@@ -1,7 +1,18 @@
import { TestBed } from '@angular/core/testing';
import { provideExperimentalZonelessChangeDetection } from '@angular/core';
import { MessageType, ProtoMessage } from './model/proto-message.model';
import {
Type,
provideExperimentalZonelessChangeDetection,
} from '@angular/core';
import {
BooleanMessage,
ListMessage,
MapMessage,
MessageConfiguration,
NumericMessage,
ProtoMessage,
StringMessage,
} from './model/proto-message.model';
import { ProtoDefinitionService } from './proto-definition.service';
let testProto = `
@@ -36,22 +47,29 @@ describe('TestService', () => {
expect(converted.name).toBe('Test');
expect(converted.values.length).toBe(8);
checkNameAndType(converted, 'hello', MessageType.String);
checkNameAndType(converted, 'hello2', MessageType.Numeric);
checkNameAndType(converted, 'hello3', MessageType.Numeric);
checkNameAndType(converted, 'hello4', MessageType.Numeric);
checkNameAndType(converted, 'hello5', MessageType.Numeric);
checkNameAndType(converted, 'hello6', MessageType.Boolean);
checkNameAndType(converted, 'hello7', MessageType.List);
checkNameAndType(converted, 'hello8', MessageType.Map);
checkNameAndType(converted, 'hello', StringMessage);
checkNameAndType(converted, 'hello2', NumericMessage);
checkNameAndType(converted, 'hello3', NumericMessage);
checkNameAndType(converted, 'hello4', NumericMessage);
checkNameAndType(converted, 'hello5', NumericMessage);
checkNameAndType(converted, 'hello6', BooleanMessage);
checkNameAndType(converted, 'hello7', ListMessage);
checkNameAndType(converted, 'hello8', MapMessage);
const listMessage = converted.values[6].configuration as ListMessage;
expect(listMessage.subConfiguration).toBeInstanceOf(StringMessage);
const mapMessage = converted.values[7].configuration as MapMessage;
expect(mapMessage.keyConfiguration).toBeInstanceOf(StringMessage);
expect(mapMessage.valueConfiguration).toBeInstanceOf(StringMessage);
});
});
const checkNameAndType = (
converted: ProtoMessage,
name: string,
type: MessageType
type: Type<MessageConfiguration>
) => {
const field = converted.values.find((value) => value.name === name);
expect(field?.type).toBe(type);
expect(field?.configuration).toBeInstanceOf(type);
};