283b622013-03-26Martin Nilsson #pike __REAL_VERSION__
71e1342013-02-17Bill Welliver  constant BSONBinary = 1;
ff17962014-08-15Martin Nilsson  protected string data; protected int subtype = 0x00;
71e1342013-02-17Bill Welliver  //!
ff17962014-08-15Martin Nilsson  protected void create(string _data, int|void _subtype)
71e1342013-02-17Bill Welliver  { subtype = _subtype; if(subtype == .BINARY_OLD) {
dd08cc2013-05-19Martin Nilsson  if( !sscanf(data, "%-4H", data) ) throw(Error.Generic("old binary data length does not match actual data length.\n"));
71e1342013-02-17Bill Welliver  } else data = _data; } int get_subtype() { return subtype; } void set_subtype(int _subtype) { subtype = _subtype; }
dd08cc2013-05-19Martin Nilsson 
ff17962014-08-15Martin Nilsson  protected int _sizeof()
71e1342013-02-17Bill Welliver  { if(subtype == .BINARY_OLD) return sizeof(data) + 4; else return sizeof(data); }
ff17962014-08-15Martin Nilsson  protected mixed cast(string type)
71e1342013-02-17Bill Welliver  { if(type == "string") {
dd08cc2013-05-19Martin Nilsson  // the docs are a little sketchy about this, do we need to NULL // terminate?
71e1342013-02-17Bill Welliver  if(subtype == .BINARY_OLD)
dd08cc2013-05-19Martin Nilsson  return sprintf("%-4H", data);
71e1342013-02-17Bill Welliver  else return data; } }