Browse files

BSON can send Nan and Inf

  • Loading branch information...
akira noda
akira noda committed Jan 25, 2019
1 parent d896276 commit a1b0661a663e539aafe39daf71156ebeb4f2ae01
Showing with 6 additions and 3 deletions.
  1. +6 −3 rosbridge_library/src/rosbridge_library/internal/
@@ -82,9 +82,10 @@
("char[]", re.compile(r'char\[[^\]]*\]'))]

binary_encoder = None
bson_only_mode = None

def get_encoder():
global binary_encoder
global binary_encoder,bson_only_mode
if binary_encoder is None:
binary_encoder_type = rospy.get_param('~binary_encoder', 'default')
bson_only_mode = rospy.get_param('~bson_only_mode', False)
@@ -130,6 +131,7 @@ def populate_instance(msg, inst):

def _from_inst(inst, rostype):
global bson_only_mode
# Special case for uint8[], we encode the string
for binary_type, expression in ros_binary_types_list_braces:
if expression.sub(binary_type, rostype) in ros_binary_types:
@@ -140,10 +142,11 @@ def _from_inst(inst, rostype):
if rostype in ros_time_types:
return {"secs": inst.secs, "nsecs": inst.nsecs}

if(bson_only_mode is None):bson_only_mode = rospy.get_param('~bson_only_mode', False)
# Check for primitive types
if rostype in ros_primitive_types:
#JSON does not support Inf and NaN. They are mapped to None and encoded as null.
if rostype in ["float32", "float64"]:
#JSON does not support Inf and NaN. They are mapped to None and encoded as null
if (not bson_only_mode) and (rostype in ["float32", "float64"]):
if math.isnan(inst) or math.isinf(inst):
return None
return inst

0 comments on commit a1b0661

Please sign in to comment.