Encode the nested protobuf into wire format.
345181
def ConvertToWireFormat(self, value):
    """"""
    output = _SerializeEntries(_GetOrderedEntries(value.GetRawData()))
    return (self.encoded_tag, VarintEncode(len(output)), output)
1323756
def convert_protodef_to_editable(proto):
    
    class Editable(object):
        def __init__(self, prot):
            self.kind = type(prot)
            self.name = prot.name
            self.comment = ""
            self.options = dict([(key.name, value) for (key, value) in prot.options.ListFields()])
            if isinstance(prot, EnumDescriptorProto):
                self.value = [convert_protodef_to_editable(x) for x in prot.value]
            elif isinstance(prot, DescriptorProto):
                self.field = [convert_protodef_to_editable(x) for x in prot.field]
                self.enum_type = [convert_protodef_to_editable(x) for x in prot.enum_type]
                self.nested_type = prot.nested_type
                self.oneof_decl = prot.oneof_decl
            elif isinstance(prot, EnumValueDescriptorProto):
                self.number = prot.number
            elif isinstance(prot, FieldDescriptorProto):
                if prot.type in [11, 14]:
                    self.ref_type = prot.type_name[1:]
                self.type = prot.type
                self.label = prot.label
            elif isinstance(prot, ServiceDescriptorProto):
                self.method = [convert_protodef_to_editable(x) for x in prot.method]
            elif isinstance(prot, MethodDescriptorProto):
                self.input_type = prot.input_type
                self.output_type = prot.output_type
            else:
                raise Exception, type(prot)

    return Editable(proto)
856827
function(data) {
      return proto.encodeStrict(data.a, data.b, data.c, data.d);
    }
1233289
def converts_to_proto(value, msg, raise_err=False):
    
    result = True
    try:
        dict_to_protobuf.dict_to_protobuf(value, msg)
    except TypeError as type_error:
        if raise_err:
            raise type_error
        result = False
    return result
49115
def _encode_buffer(string, f):
	""""""
	if isinstance(string, str):
		string = string.encode()
	f.write(str(len(string)).encode())
	f.write(_TYPE_SEP)
	f.write(string)
286620
function encode(args) {
  const argc = args.length;
  let len = 1;
  let off = 0;
  var i;

  // data length
  for (i = 0; i < argc; i += 1) {
    len += 4 + args[i].length;
  }

  // buffer
  const buf = Buffer.alloc(len);

  // pack meta
  buf[off += 1] = (VERSION << 4) | argc;

  // pack args
  for (i = 0; i < argc; i += 1) {
    const arg = args[i];

    buf.writeUInt32BE(arg.length, off);
    off += 4;

    arg.copy(buf, off);
    off += arg.length;
  }

  return buf;
}
968080
def from_string(proto_str):
    '''
    
    '''
    _, proto_file = tempfile.mkstemp(suffix='.proto')

    with open(proto_file, 'w+') as proto_f:
        proto_f.write(proto_str)

    return from_file(proto_file)
762440
public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
	{
		if ($object === null) {
			$object = new Location();
		}

		if ($end === null) {
			$end = strlen($input);
		}

		while ($start < $end) {
			$tag = Binary::decodeVarint($input, $start);
			$wireType = $tag & 0x7;
			$number = $tag >> 3;
			switch ($number) {
				case 1:
					if ($wireType !== 2) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
					}
					if (!(isset($object->path) && is_array($object->path))) {
						$object->path = array();
					}
					$packedLength = Binary::decodeVarint($input, $start);
					$expectedPacked = $start + $packedLength;
					if ($expectedPacked > $end) {
						throw new ProtobufException('Not enough data.');
					}
					while ($start < $expectedPacked) {
						$object->path[] = Binary::decodeVarint($input, $start);
					}
					if ($start !== $expectedPacked) {
						throw new ProtobufException('Unexpected start. Expected ' . $expectedPacked . ', got ' . $start . '.', $number);
					}
					break;
				case 2:
					if ($wireType !== 2) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
					}
					if (!(isset($object->span) && is_array($object->span))) {
						$object->span = array();
					}
					$packedLength = Binary::decodeVarint($input, $start);
					$expectedPacked = $start + $packedLength;
					if ($expectedPacked > $end) {
						throw new ProtobufException('Not enough data.');
					}
					while ($start < $expectedPacked) {
						$object->span[] = Binary::decodeVarint($input, $start);
					}
					if ($start !== $expectedPacked) {
						throw new ProtobufException('Unexpected start. Expected ' . $expectedPacked . ', got ' . $start . '.', $number);
					}
					break;
				case 3:
					if ($wireType !== 2) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
					}
					$length = Binary::decodeVarint($input, $start);
					$expectedStart = $start + $length;
					if ($expectedStart > $end) {
						throw new ProtobufException('Not enough data.');
					}
					$object->leadingComments = substr($input, $start, $length);
					$start += $length;
					if ($start !== $expectedStart) {
						throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
					}
					break;
				case 4:
					if ($wireType !== 2) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
					}
					$length = Binary::decodeVarint($input, $start);
					$expectedStart = $start + $length;
					if ($expectedStart > $end) {
						throw new ProtobufException('Not enough data.');
					}
					$object->trailingComments = substr($input, $start, $length);
					$start += $length;
					if ($start !== $expectedStart) {
						throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
					}
					break;
				case 6:
					if ($wireType !== 2) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
					}
					if (!(isset($object->leadingDetachedComments) && is_array($object->leadingDetachedComments))) {
						$object->leadingDetachedComments = array();
					}
					$length = Binary::decodeVarint($input, $start);
					$expectedStart = $start + $length;
					if ($expectedStart > $end) {
						throw new ProtobufException('Not enough data.');
					}
					$object->leadingDetachedComments[] = substr($input, $start, $length);
					$start += $length;
					if ($start !== $expectedStart) {
						throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
					}
					break;
				default:
					switch ($wireType) {
						case 0:
							Binary::decodeVarint($input, $start);
							break;
						case 1:
							$start += 8;
							break;
						case 2:
							$start += Binary::decodeVarint($input, $start);
							break;
						case 5:
							$start += 4;
							break;
						default:
							throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
					}
			}
		}

		return $object;
	}
1015120
def encode_nested_bytes(item)
      if item.instance_of?(String)
        return item if item.size == 1 && item.ord < PRIMITIVE_PREFIX_OFFSET
        prefix = length_prefix item.size, PRIMITIVE_PREFIX_OFFSET
      else # list
        item = item.map {|x| encode_nested_bytes(x) }.join
        prefix = length_prefix item.size, LIST_PREFIX_OFFSET
      end

      "#{prefix}#{item}"
    end
329181
def to_protobuf(self) -> LinkItemProto:
        
        result = LinkItemProto()
        result.name = self._name
        result.time.CopyFrom(datetime_to_timestamp(self._time))
        return result
945306
def _build_protobuf(self):
        
        pb = _pb_from_query(self._query)

        start_cursor = self.next_page_token
        if start_cursor is not None:
            pb.start_cursor = base64.urlsafe_b64decode(start_cursor)

        end_cursor = self._end_cursor
        if end_cursor is not None:
            pb.end_cursor = base64.urlsafe_b64decode(end_cursor)

        if self.max_results is not None:
            pb.limit.value = self.max_results - self.num_results

        if start_cursor is None and self._offset is not None:
            # NOTE: We don't need to add an offset to the request protobuf
            #       if we are using an existing cursor, because the offset
            #       is only relative to the start of the result set, not
            #       relative to each page (this method is called per-page)
            pb.offset = self._offset

        return pb
1259655
function encode (schema, doc, toEncrypt) {
    if (!doc) return false
    var method = (toEncrypt) ? encrypt : decrypt
      , obj = (doc.toObject) ? doc.toObject() : doc

    // Traverse through all schema paths
    schema.eachPath(function (name, path) {
      var val = nestedPath(doc, name)

      // ObjectID paths
      if (path.instance === 'ObjectID' && val) {
        nestedPath(obj, name, method(val.toString()))
      }

      if (path.casterConstructor) {
        // Array of DBRefs
        if (!!~path.casterConstructor.toString().indexOf('ObjectId')) {
          nestedPath(obj, name).forEach(function (v, k) {
            nestedPath(obj, name)[k] = method(val[k].toString())
          })     
        // Array of embedded schemas
        } else if (!!~path.casterConstructor.toString().indexOf('EmbeddedDocument')) {
          nestedPath(obj, name).forEach(function (v, k) {
            nestedPath(obj, name)[k] = encode(path.schema, val[k], toEncrypt)
          })
        }
      }
    })
    return obj
  }
1033880
def to_protobuf(self) -> SaveStateProto:
        
        result = SaveStateProto()
        result.version = str(self.version)
        result.last_update.CopyFrom(datetime_to_timestamp(self.last_update))
        result.plugin_info.CopyFrom(self.plugin_info.to_protobuf())
        for key, link_item in self.link_item_dict.items():
            result.data[key].CopyFrom(link_item.to_protobuf())
        return result
1175553
def _encode_payload(data, headers=None):
    ""
    prolog = "CONTENT_LENGTH\0%d\0SCGI\x001\0" % len(data)
    if headers:
        prolog += _encode_headers(headers)

    return _encode_netstring(prolog) + data
972588
def ConvertToWireFormat(self, value):
    """"""
    # Is it a protobuf-based value?
    if hasattr(value.__class__, "protobuf"):
      if value.__class__.protobuf:
        type_name = ("type.googleapis.com/%s" %
                     value.__class__.protobuf.__name__)
      else:
        type_name = value.__class__.__name__
      data = value.SerializeToString()
    # Is it a primitive value?
    elif hasattr(value.__class__, "data_store_type"):
      wrapper_cls = self.__class__.WRAPPER_BY_TYPE[
          value.__class__.data_store_type]
      wrapped_data = wrapper_cls()
      wrapped_data.value = value.SerializeToDataStore()

      type_name = ("type.googleapis.com/google.protobuf.%s" %
                   wrapper_cls.__name__)
      data = wrapped_data.SerializeToString()
    else:
      raise ValueError("Can't convert value %s to an protobuf.Any value." %
                       value)

    any_value = AnyValue(type_url=type_name, value=data)
    output = _SerializeEntries(_GetOrderedEntries(any_value.GetRawData()))

    return (self.encoded_tag, VarintEncode(len(output)), output)
869776
public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
	{
		if ($object === null) {
			$object = new MessageOptions();
		}

		if ($end === null) {
			$end = strlen($input);
		}

		while ($start < $end) {
			$tag = Binary::decodeVarint($input, $start);
			$wireType = $tag & 0x7;
			$number = $tag >> 3;
			switch ($number) {
				case 1:
					if ($wireType !== 0) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
					}
					$object->messageSetWireFormat = (bool)Binary::decodeVarint($input, $start);
					break;
				case 2:
					if ($wireType !== 0) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
					}
					$object->noStandardDescriptorAccessor = (bool)Binary::decodeVarint($input, $start);
					break;
				case 3:
					if ($wireType !== 0) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
					}
					$object->deprecated = (bool)Binary::decodeVarint($input, $start);
					break;
				case 7:
					if ($wireType !== 0) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
					}
					$object->mapEntry = (bool)Binary::decodeVarint($input, $start);
					break;
				case 999:
					if ($wireType !== 2) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
					}
					if (!(isset($object->uninterpretedOption) && is_array($object->uninterpretedOption))) {
						$object->uninterpretedOption = array();
					}
					$length = Binary::decodeVarint($input, $start);
					$expectedStart = $start + $length;
					if ($expectedStart > $end) {
						throw new ProtobufException('Not enough data.');
					}
					$object->uninterpretedOption[] = UninterpretedOptionMeta::fromProtobuf($input, null, $start, $start + $length);
					if ($start !== $expectedStart) {
						throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
					}
					break;
				default:
					switch ($wireType) {
						case 0:
							Binary::decodeVarint($input, $start);
							break;
						case 1:
							$start += 8;
							break;
						case 2:
							$start += Binary::decodeVarint($input, $start);
							break;
						case 5:
							$start += 4;
							break;
						default:
							throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
					}
			}
		}

		return $object;
	}
1169722
public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
	{
		if ($object === null) {
			$object = new Embedded();
		}

		if ($end === null) {
			$end = strlen($input);
		}

		while ($start < $end) {
			$tag = Binary::decodeVarint($input, $start);
			$wireType = $tag & 0x7;
			$number = $tag >> 3;
			switch ($number) {
				case 1:
					if ($wireType !== 2) {
						throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
					}
					$length = Binary::decodeVarint($input, $start);
					$expectedStart = $start + $length;
					if ($expectedStart > $end) {
						throw new ProtobufException('Not enough data.');
					}
					$object->x = substr($input, $start, $length);
					$start += $length;
					if ($start !== $expectedStart) {
						throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
					}
					break;
				default:
					switch ($wireType) {
						case 0:
							Binary::decodeVarint($input, $start);
							break;
						case 1:
							$start += 8;
							break;
						case 2:
							$start += Binary::decodeVarint($input, $start);
							break;
						case 5:
							$start += 4;
							break;
						default:
							throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
					}
			}
		}

		return $object;
	}