Module: BSON::Float

Defined in:
lib/bson/float.rb

Overview

Injects behaviour for encoding and decoding floating point values to and from # raw bytes as specified by the BSON spec.

See Also:

Since:

  • 2.0.0

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

BSON_TYPE =

A floating point is type 0x01 in the BSON spec.

Since:

  • 2.0.0

1.chr.force_encoding(BINARY).freeze
PACK =

The pack directive is for 8 byte floating points.

Since:

  • 2.0.0

"E".freeze

Instance Method Summary collapse

Instance Method Details

#to_bson(encoded = ''.force_encoding(BINARY)) ⇒ String

Get the floating point as encoded BSON.

Examples:

Get the floating point as encoded BSON.

1.221311.to_bson

Returns:

  • (String)

    The encoded string.

See Also:

Since:

  • 2.0.0



45
46
47
# File 'lib/bson/float.rb', line 45

def to_bson(encoded = ''.force_encoding(BINARY))
  encoded << [ self ].pack(PACK)
end