Skip to content

Commit

Permalink
add null support
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Jun 20, 2024
1 parent 43a9346 commit eb56503
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 39 deletions.
8 changes: 5 additions & 3 deletions pkgs/record_use/lib/src/data_classes/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ extension IdentifierStorageExt on pb_storage.Identifier {

extension FieldValueExt on pb_shared.FieldValue {
Object toObject() => switch (whichValue()) {
pb_shared.FieldValue_Value.map =>
map.value.map((key, value) => MapEntry(key, value.toObject())),
pb_shared.FieldValue_Value.list => list.value.map((e) => e.toObject()),
pb_shared.FieldValue_Value.mapValue =>
mapValue.value.map((key, value) => MapEntry(key, value.toObject())),
pb_shared.FieldValue_Value.listValue =>
listValue.value.map((e) => e.toObject()),
pb_shared.FieldValue_Value.intValue => intValue,
pb_shared.FieldValue_Value.doubleValue => doubleValue,
pb_shared.FieldValue_Value.boolValue => boolValue,
pb_shared.FieldValue_Value.stringValue => stringValue,
pb_shared.FieldValue_Value.nullValue => nullValue,
pb_shared.FieldValue_Value.notSet => throw UnimplementedError(),
};
}
65 changes: 42 additions & 23 deletions pkgs/record_use/lib/src/proto/usages_shared.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -451,30 +451,32 @@ class Field extends $pb.GeneratedMessage {
}

enum FieldValue_Value {
map,
list,
mapValue,
listValue,
intValue,
doubleValue,
boolValue,
stringValue,
nullValue,
notSet
}

class FieldValue extends $pb.GeneratedMessage {
factory FieldValue({
StringMapValue? map,
ListValue? list,
StringMapValue? mapValue,
ListValue? listValue,
$core.int? intValue,
$core.double? doubleValue,
$core.bool? boolValue,
$core.String? stringValue,
$core.bool? nullValue,
}) {
final $result = create();
if (map != null) {
$result.map = map;
if (mapValue != null) {
$result.mapValue = mapValue;
}
if (list != null) {
$result.list = list;
if (listValue != null) {
$result.listValue = listValue;
}
if (intValue != null) {
$result.intValue = intValue;
Expand All @@ -488,6 +490,9 @@ class FieldValue extends $pb.GeneratedMessage {
if (stringValue != null) {
$result.stringValue = stringValue;
}
if (nullValue != null) {
$result.nullValue = nullValue;
}
return $result;
}
FieldValue._() : super();
Expand All @@ -499,28 +504,30 @@ class FieldValue extends $pb.GeneratedMessage {
create()..mergeFromJson(i, r);

static const $core.Map<$core.int, FieldValue_Value> _FieldValue_ValueByTag = {
1: FieldValue_Value.map,
2: FieldValue_Value.list,
1: FieldValue_Value.mapValue,
2: FieldValue_Value.listValue,
3: FieldValue_Value.intValue,
4: FieldValue_Value.doubleValue,
5: FieldValue_Value.boolValue,
6: FieldValue_Value.stringValue,
7: FieldValue_Value.nullValue,
0: FieldValue_Value.notSet
};
static final $pb.BuilderInfo _i = $pb.BuilderInfo(
_omitMessageNames ? '' : 'FieldValue',
package: const $pb.PackageName(_omitMessageNames ? '' : 'usages_shared'),
createEmptyInstance: create)
..oo(0, [1, 2, 3, 4, 5, 6])
..aOM<StringMapValue>(1, _omitFieldNames ? '' : 'map',
..oo(0, [1, 2, 3, 4, 5, 6, 7])
..aOM<StringMapValue>(1, _omitFieldNames ? '' : 'mapValue',
subBuilder: StringMapValue.create)
..aOM<ListValue>(2, _omitFieldNames ? '' : 'list',
..aOM<ListValue>(2, _omitFieldNames ? '' : 'listValue',
subBuilder: ListValue.create)
..a<$core.int>(3, _omitFieldNames ? '' : 'intValue', $pb.PbFieldType.O3)
..a<$core.double>(
4, _omitFieldNames ? '' : 'doubleValue', $pb.PbFieldType.OD)
..aOB(5, _omitFieldNames ? '' : 'boolValue')
..aOS(6, _omitFieldNames ? '' : 'stringValue')
..aOB(7, _omitFieldNames ? '' : 'nullValue')
..hasRequiredFields = false;

@$core.Deprecated('Using this can add significant overhead to your binary. '
Expand Down Expand Up @@ -548,32 +555,32 @@ class FieldValue extends $pb.GeneratedMessage {
void clearValue() => clearField($_whichOneof(0));

@$pb.TagNumber(1)
StringMapValue get map => $_getN(0);
StringMapValue get mapValue => $_getN(0);
@$pb.TagNumber(1)
set map(StringMapValue v) {
set mapValue(StringMapValue v) {
setField(1, v);
}

@$pb.TagNumber(1)
$core.bool hasMap() => $_has(0);
$core.bool hasMapValue() => $_has(0);
@$pb.TagNumber(1)
void clearMap() => clearField(1);
void clearMapValue() => clearField(1);
@$pb.TagNumber(1)
StringMapValue ensureMap() => $_ensure(0);
StringMapValue ensureMapValue() => $_ensure(0);

@$pb.TagNumber(2)
ListValue get list => $_getN(1);
ListValue get listValue => $_getN(1);
@$pb.TagNumber(2)
set list(ListValue v) {
set listValue(ListValue v) {
setField(2, v);
}

@$pb.TagNumber(2)
$core.bool hasList() => $_has(1);
$core.bool hasListValue() => $_has(1);
@$pb.TagNumber(2)
void clearList() => clearField(2);
void clearListValue() => clearField(2);
@$pb.TagNumber(2)
ListValue ensureList() => $_ensure(1);
ListValue ensureListValue() => $_ensure(1);

@$pb.TagNumber(3)
$core.int get intValue => $_getIZ(2);
Expand Down Expand Up @@ -622,6 +629,18 @@ class FieldValue extends $pb.GeneratedMessage {
$core.bool hasStringValue() => $_has(5);
@$pb.TagNumber(6)
void clearStringValue() => clearField(6);

@$pb.TagNumber(7)
$core.bool get nullValue => $_getBF(6);
@$pb.TagNumber(7)
set nullValue($core.bool v) {
$_setBool(6, v);
}

@$pb.TagNumber(7)
$core.bool hasNullValue() => $_has(6);
@$pb.TagNumber(7)
void clearNullValue() => clearField(7);
}

class ListValue extends $pb.GeneratedMessage {
Expand Down
20 changes: 11 additions & 9 deletions pkgs/record_use/lib/src/proto/usages_shared.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,28 @@ const FieldValue$json = {
'1': 'FieldValue',
'2': [
{
'1': 'map',
'1': 'map_value',
'3': 1,
'4': 1,
'5': 11,
'6': '.usages_shared.StringMapValue',
'9': 0,
'10': 'map'
'10': 'mapValue'
},
{
'1': 'list',
'1': 'list_value',
'3': 2,
'4': 1,
'5': 11,
'6': '.usages_shared.ListValue',
'9': 0,
'10': 'list'
'10': 'listValue'
},
{'1': 'int_value', '3': 3, '4': 1, '5': 5, '9': 0, '10': 'intValue'},
{'1': 'double_value', '3': 4, '4': 1, '5': 1, '9': 0, '10': 'doubleValue'},
{'1': 'bool_value', '3': 5, '4': 1, '5': 8, '9': 0, '10': 'boolValue'},
{'1': 'string_value', '3': 6, '4': 1, '5': 9, '9': 0, '10': 'stringValue'},
{'1': 'null_value', '3': 7, '4': 1, '5': 8, '9': 0, '10': 'nullValue'},
],
'8': [
{'1': 'value'},
Expand All @@ -224,11 +225,12 @@ const FieldValue$json = {

/// Descriptor for `FieldValue`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List fieldValueDescriptor = $convert.base64Decode(
'CgpGaWVsZFZhbHVlEjEKA21hcBgBIAEoCzIdLnVzYWdlc19zaGFyZWQuU3RyaW5nTWFwVmFsdW'
'VIAFIDbWFwEi4KBGxpc3QYAiABKAsyGC51c2FnZXNfc2hhcmVkLkxpc3RWYWx1ZUgAUgRsaXN0'
'Eh0KCWludF92YWx1ZRgDIAEoBUgAUghpbnRWYWx1ZRIjCgxkb3VibGVfdmFsdWUYBCABKAFIAF'
'ILZG91YmxlVmFsdWUSHwoKYm9vbF92YWx1ZRgFIAEoCEgAUglib29sVmFsdWUSIwoMc3RyaW5n'
'X3ZhbHVlGAYgASgJSABSC3N0cmluZ1ZhbHVlQgcKBXZhbHVl');
'CgpGaWVsZFZhbHVlEjwKCW1hcF92YWx1ZRgBIAEoCzIdLnVzYWdlc19zaGFyZWQuU3RyaW5nTW'
'FwVmFsdWVIAFIIbWFwVmFsdWUSOQoKbGlzdF92YWx1ZRgCIAEoCzIYLnVzYWdlc19zaGFyZWQu'
'TGlzdFZhbHVlSABSCWxpc3RWYWx1ZRIdCglpbnRfdmFsdWUYAyABKAVIAFIIaW50VmFsdWUSIw'
'oMZG91YmxlX3ZhbHVlGAQgASgBSABSC2RvdWJsZVZhbHVlEh8KCmJvb2xfdmFsdWUYBSABKAhI'
'AFIJYm9vbFZhbHVlEiMKDHN0cmluZ192YWx1ZRgGIAEoCUgAUgtzdHJpbmdWYWx1ZRIfCgpudW'
'xsX3ZhbHVlGAcgASgISABSCW51bGxWYWx1ZUIHCgV2YWx1ZQ==');

@$core.Deprecated('Use listValueDescriptor instead')
const ListValue$json = {
Expand Down
5 changes: 3 additions & 2 deletions pkgs/record_use/lib/src/proto/usages_shared.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ message Field {

message FieldValue {
oneof value {
StringMapValue map = 1;
ListValue list = 2;
StringMapValue map_value = 1;
ListValue list_value = 2;
int32 int_value = 3;
double double_value = 4;
bool bool_value = 5;
string string_value = 6;
bool null_value = 7;
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkgs/record_use/test/testdata/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final Usages recordedUses = Usages(
0: FieldValue(stringValue: 'lib_SHA1'),
2: FieldValue(intValue: 0),
4: FieldValue(
map: StringMapValue(
mapValue: StringMapValue(
value: {
'key': FieldValue(intValue: 99),
},
Expand All @@ -104,7 +104,7 @@ final Usages recordedUses = Usages(
named: {
'leroy': FieldValue(stringValue: 'jenkins'),
'albert': FieldValue(
list: ListValue(
listValue: ListValue(
value: [
FieldValue(stringValue: 'camus'),
FieldValue(stringValue: 'einstein'),
Expand Down

0 comments on commit eb56503

Please sign in to comment.