module Pb::Serializer
Constants
- VERSION
Public Class Methods
build_default_mask(descriptor)
click to toggle source
@param [Google::Protobuf::Descriptor]
# File lib/pb/serializer.rb, line 69 def build_default_mask(descriptor) set = descriptor.each_with_object(Set[]) do |fd, m| case fd.type when :message case fd.submsg_name when "google.protobuf.Timestamp", "google.protobuf.StringValue", "google.protobuf.Int32Value" , "google.protobuf.Int64Value" , "google.protobuf.UInt32Value", "google.protobuf.UInt64Value", "google.protobuf.FloatValue" , "google.protobuf.DoubleValue", "google.protobuf.BoolValue" , "google.protobuf.BytesValue" then m << fd.name.to_sym else m << { fd.name.to_sym => build_default_mask(fd.subtype) } end else m << fd.name.to_sym end end set.to_a end
configuration()
click to toggle source
@return [Pb::Serializer::Configuration]
# File lib/pb/serializer.rb, line 59 def configuration @configuraiton ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
@example
Pb::Serializer.configuration do |c| c.missing_field_behavior = :raise # :raise, :warn or :ignore (defualt: :raise) end
@yield [c] @yieldparam [Configuration] config
# File lib/pb/serializer.rb, line 54 def configure yield configuration end
logger()
click to toggle source
@return [Logger]
# File lib/pb/serializer.rb, line 64 def logger configuration.logger end
normalize_mask(input)
click to toggle source
@param [Google::Protobuf::FieldMask, Symbol, Array<(Symbol,Hash)>, Hash{Symbol=>(Array,Symbol,Hash)}] @return [Hash{Symbol=>(Array,Hash)}]
# File lib/pb/serializer.rb, line 109 def normalize_mask(input) if input.kind_of?(Google::Protobuf::FieldMask) input = parse_field_mask(input) end normalized = {} input = [input] if input.kind_of?(Hash) Array(input).each do |el| case el when Symbol normalized[el] ||= [] when Hash el.each do |k, v| v = [v] if v.kind_of?(Hash) normalized[k] ||= [] normalized[k].push(*Array(v)) end else raise "not supported field mask type: #{input.class}" end end normalized end
parse_field_mask(field_mask)
click to toggle source
@param [Google::Protobuf::FieldMask] @return [Array]
# File lib/pb/serializer.rb, line 97 def parse_field_mask(field_mask) unless field_mask.kind_of?(Google::Protobuf::FieldMask) raise ArgumentError, "expected Google::Protobuf::FieldMask, but got #{field_mask.class}" end field_mask.paths.map do |path| path.split(".").reverse.inject(nil) { |h, key| h.nil? ? key.to_sym : { key.to_sym => [h].compact } } end end