Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 13 additions & 58 deletions protobuf/lib/protobuf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,16 @@
/// [1]: https://developers.google.com/protocol-buffers
library;

import 'dart:collection' show ListBase, MapBase;
import 'dart:convert'
show
Utf8Decoder,
Utf8Encoder,
base64Decode,
base64Encode,
jsonDecode,
jsonEncode;
import 'dart:math' as math;
import 'dart:typed_data' show ByteData, Endian, Uint8List;

import 'package:fixnum/fixnum.dart' show Int64;
import 'package:meta/meta.dart' show UseResult;

import 'src/protobuf/json_parsing_context.dart';
import 'src/protobuf/permissive_compare.dart';
import 'src/protobuf/type_registry.dart';

export 'src/protobuf/type_registry.dart' show TypeRegistry;

part 'src/protobuf/annotations.dart';
part 'src/protobuf/builder_info.dart';
part 'src/protobuf/coded_buffer.dart';
part 'src/protobuf/coded_buffer_reader.dart';
part 'src/protobuf/coded_buffer_writer.dart';
part 'src/protobuf/consts.dart';
part 'src/protobuf/exceptions.dart';
part 'src/protobuf/extension.dart';
part 'src/protobuf/extension_field_set.dart';
part 'src/protobuf/extension_registry.dart';
part 'src/protobuf/field_error.dart';
part 'src/protobuf/field_info.dart';
part 'src/protobuf/field_set.dart';
part 'src/protobuf/field_type.dart';
part 'src/protobuf/generated_message.dart';
part 'src/protobuf/generated_service.dart';
part 'src/protobuf/json.dart';
part 'src/protobuf/message_set.dart';
part 'src/protobuf/pb_list.dart';
part 'src/protobuf/pb_map.dart';
part 'src/protobuf/proto3_json.dart';
part 'src/protobuf/protobuf_enum.dart';
part 'src/protobuf/rpc_client.dart';
part 'src/protobuf/unknown_field_set.dart';
part 'src/protobuf/unpack.dart';
part 'src/protobuf/utils.dart';
part 'src/protobuf/wire_format.dart';

// TODO(sra): Use `Int64.parse()` when available:
// https://github.com/dart-lang/fixnum/issues/18.
/// @nodoc
Int64 parseLongInt(String text) {
if (text.startsWith('0x')) return Int64.parseHex(text.substring(2));
if (text.startsWith('+0x')) return Int64.parseHex(text.substring(3));
if (text.startsWith('-0x')) return -Int64.parseHex(text.substring(3));
return Int64.parseInt(text);
}
export 'src/protobuf/internal.dart'
hide
BuilderInfoInternalExtension,
EnumFieldInfoExtension,
ExtensionFieldSet,
ExtensionFieldSetInternalExtension,
FieldInfoInternalExtension,
FieldSet,
FieldSetInternalExtension,
GeneratedMessageInternalExtension,
MapFieldInfoInternalExtension,
mapKeyFieldNumber,
mapValueFieldNumber;
2 changes: 1 addition & 1 deletion protobuf/lib/src/protobuf/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of '../../protobuf.dart';
part of 'internal.dart';

/// Annotation for marking accessors that belong together.
class TagNumber {
Expand Down
51 changes: 35 additions & 16 deletions protobuf/lib/src/protobuf/builder_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of '../../protobuf.dart';
part of 'internal.dart';

/// Per-message type setup.
class BuilderInfo {
Expand All @@ -28,7 +28,7 @@ class BuilderInfo {
final Map<String, FieldInfo> byName = <String, FieldInfo>{};

/// Mapping from `oneof` field [FieldInfo.tagNumber]s to the their indices in
/// [_FieldSet._oneofCases].
/// [FieldSet._oneofCases].
final Map<int, int> oneofs = <int, int>{};

/// Whether the message has extension fields.
Expand Down Expand Up @@ -105,7 +105,7 @@ class BuilderInfo {
name,
tagNumber,
index,
PbFieldType.M,
PbFieldTypeInternal.M,
keyFieldType,
valueFieldType,
mapEntryBuilderInfo,
Expand Down Expand Up @@ -179,13 +179,13 @@ class BuilderInfo {
);
}

/// Adds PbFieldType.OS String with no default value to reduce generated
/// Adds PbFieldTypeInternal.OS String with no default value to reduce generated
/// code size.
void aOS(int tagNumber, String name, {String? protoName}) {
add<String>(
tagNumber,
name,
PbFieldType.OS,
PbFieldTypeInternal.OS,
null,
null,
null,
Expand All @@ -194,26 +194,26 @@ class BuilderInfo {
);
}

/// Adds PbFieldType.PS String with no default value.
/// Adds PbFieldTypeInternal.PS String with no default value.
void pPS(int tagNumber, String name, {String? protoName}) {
addRepeated<String>(
tagNumber,
name,
PbFieldType.PS,
getCheckFunction(PbFieldType.PS),
PbFieldTypeInternal.PS,
getCheckFunction(PbFieldTypeInternal.PS),
null,
null,
null,
protoName: protoName,
);
}

/// Adds PbFieldType.QS String with no default value.
/// Adds PbFieldTypeInternal.QS String with no default value.
void aQS(int tagNumber, String name, {String? protoName}) {
add<String>(
tagNumber,
name,
PbFieldType.QS,
PbFieldTypeInternal.QS,
null,
null,
null,
Expand All @@ -227,7 +227,7 @@ class BuilderInfo {
add<Int64>(
tagNumber,
name,
PbFieldType.O6,
PbFieldTypeInternal.O6,
Int64.ZERO,
null,
null,
Expand All @@ -241,7 +241,7 @@ class BuilderInfo {
add<bool>(
tagNumber,
name,
PbFieldType.OB,
PbFieldTypeInternal.OB,
null,
null,
null,
Expand Down Expand Up @@ -274,7 +274,10 @@ class BuilderInfo {

// Repeated, not a message, group, or enum.
void p<T>(int tagNumber, String name, int fieldType, {String? protoName}) {
assert(!_isGroupOrMessage(fieldType) && !_isEnum(fieldType));
assert(
!PbFieldTypeInternal.isGroupOrMessage(fieldType) &&
!PbFieldTypeInternal.isEnum(fieldType),
);
addRepeated<T>(
tagNumber,
name,
Expand All @@ -298,7 +301,10 @@ class BuilderInfo {
ProtobufEnum? defaultEnumValue,
String? protoName,
}) {
assert(_isGroupOrMessage(fieldType) || _isEnum(fieldType));
assert(
PbFieldTypeInternal.isGroupOrMessage(fieldType) ||
PbFieldTypeInternal.isEnum(fieldType),
);
addRepeated<T>(
tagNumber,
name,
Expand All @@ -321,7 +327,7 @@ class BuilderInfo {
add<T>(
tagNumber,
name,
PbFieldType.OM,
PbFieldTypeInternal.OM,
GeneratedMessage._defaultMakerFor<T>(subBuilder),
subBuilder,
null,
Expand All @@ -339,7 +345,7 @@ class BuilderInfo {
add<T>(
tagNumber,
name,
PbFieldType.QM,
PbFieldTypeInternal.QM,
GeneratedMessage._defaultMakerFor<T>(subBuilder),
subBuilder,
null,
Expand Down Expand Up @@ -487,3 +493,16 @@ class BuilderInfo {
?.call(rawValue);
}
}

extension BuilderInfoInternalExtension on BuilderInfo {
GeneratedMessage makeEmptyMessage(
int tagNumber,
ExtensionRegistry? extensionRegistry,
) => _makeEmptyMessage(tagNumber, extensionRegistry);

ProtobufEnum? decodeEnum(
int tagNumber,
ExtensionRegistry? registry,
int rawValue,
) => _decodeEnum(tagNumber, registry, rawValue);
}
Loading
Loading