Module: Gqldb::Wire
- Defined in:
- lib/tina4_ultipa/pb.rb
Overview
---- wire encoders --------------------------------------------------------
Class Method Summary collapse
- .tag(buf, field_no, wire_type) ⇒ Object
- .varint(buf, n) ⇒ Object
- .write_bool(buf, field_no, b) ⇒ Object
- .write_bytes(buf, field_no, bytes) ⇒ Object
- .write_string(buf, field_no, str) ⇒ Object
- .write_varint(buf, field_no, n) ⇒ Object
Class Method Details
.tag(buf, field_no, wire_type) ⇒ Object
92 93 94 |
# File 'lib/tina4_ultipa/pb.rb', line 92 def tag(buf, field_no, wire_type) varint(buf, (field_no << 3) | wire_type) end |
.varint(buf, n) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/tina4_ultipa/pb.rb', line 82 def varint(buf, n) # Handle negative numbers as two's-complement uint64. n = (1 << 64) + n if n.negative? while n >= 0x80 buf << ((n & 0x7F) | 0x80) n >>= 7 end buf << (n & 0x7F) end |
.write_bool(buf, field_no, b) ⇒ Object
114 115 116 117 118 |
# File 'lib/tina4_ultipa/pb.rb', line 114 def write_bool(buf, field_no, b) return unless b tag(buf, field_no, 0) varint(buf, 1) end |
.write_bytes(buf, field_no, bytes) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/tina4_ultipa/pb.rb', line 96 def write_bytes(buf, field_no, bytes) return if bytes.nil? || bytes.empty? tag(buf, field_no, 2) varint(buf, bytes.bytesize) buf << bytes.b end |
.write_string(buf, field_no, str) ⇒ Object
103 104 105 106 |
# File 'lib/tina4_ultipa/pb.rb', line 103 def write_string(buf, field_no, str) return if str.nil? || str.empty? write_bytes(buf, field_no, str.dup.force_encoding("BINARY")) end |
.write_varint(buf, field_no, n) ⇒ Object
108 109 110 111 112 |
# File 'lib/tina4_ultipa/pb.rb', line 108 def write_varint(buf, field_no, n) return if n.zero? tag(buf, field_no, 0) varint(buf, n) end |