Class: String
Instance Attribute Summary collapse
-
#cbor_warnings ⇒ Object
Returns the value of attribute cbor_warnings.
Instance Method Summary collapse
- #b ⇒ Object
- #cbor_diagnostic(options = {}) ⇒ Object
- #hexbytes(sep = '') ⇒ Object
- #to_json_514_workaround ⇒ Object
Instance Attribute Details
#cbor_warnings ⇒ Object
Returns the value of attribute cbor_warnings.
21 22 23 |
# File 'lib/cbor-pretty.rb', line 21 def cbor_warnings @cbor_warnings end |
Instance Method Details
#b ⇒ Object
47 48 49 |
# File 'lib/cbor-diagnostic.rb', line 47 def b dup.force_encoding(Encoding::BINARY) end |
#cbor_diagnostic(options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cbor-diagnostic.rb', line 54 def cbor_diagnostic( = {}) if lengths = cbor_stream? pos = 0 "(_ #{lengths.map{|l| r = self[pos, l].cbor_diagnostic(); pos += l; r}.join(", ")})" else if encoding == Encoding::BINARY if [:try_decode_embedded] && self != '' begin rest = self result = [] while rest != '' dv, rest = CBOR.decode_with_rest(rest) result << dv end return "<< #{result.map{|x| x.cbor_diagnostic()}.join(", ")} >>" rescue StandardError => e # that didn't work out, so continue with other options # puts e.backtrace end end if [:bytes_as_text] && (u8 = dup.force_encoding(Encoding::UTF_8)).valid_encoding? "'#{u8.cbor_diagnostic(bytes_as_text: true, utf8: [:utf8] )[1..-2].gsub(/(')|(\\")|(\\.)|([^\\']+)/) { if $1 "\\'" elsif $2 "\"" elsif $3 $3 elsif $4 $4 else fail end}}'" else "h'#{hexbytes}'" end else if [:utf8] to_json else to_json.encode(Encoding::UTF_16BE).bytes.each_slice(2).map { |c1, c2| c = (c1 << 8)+c2; c < 128 ? c.chr : '\u%04x' % c }.join end end end end |
#hexbytes(sep = '') ⇒ Object
13 14 15 |
# File 'lib/cbor-pretty.rb', line 13 def hexbytes(sep = '') bytes.map{|x| HEX_FORMAT % x}.join(sep) end |
#to_json_514_workaround ⇒ Object
16 17 18 19 20 |
# File 'lib/cbor-pretty.rb', line 16 def to_json_514_workaround ret = to_json ret.encode(Encoding::UTF_16BE) # exception if bad ret end |