Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Jun 20, 2018

No description provided.

@ghost ghost force-pushed the GetBytesMethod branch from 07c728c to c8d6ade Compare June 20, 2018 17:33
}

public static int GetBytes(Variant value, BinaryMode mode, byte[] buffer, int bufferIndex)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that bufferOffset would be a better name for the last argument.

Also, var below?

writer.Write(value);
}

return (int)ms.Position;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to manipulate the type here, rather than using the more natural long throughout these methods?

(I realise we are unlikely to be writing very many 2GB variants...)

Copy link
Author

@ghost ghost Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MemoryBuffer class is inconsistent. The offset/index you can pass in is an int, not sure why Position would be a long then. I mainly cast it here so the client doesn't have to do it. Also arrays with indexes > max int are quite hard to deal with. You need to use Array.GetValue() instead of the bracket indexers.

m_stream.Write(BitConverter.GetBytes((int)m_mode), 0, 4);
}

// This doesn't seem to support Unicode properly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weren't you going to change this so that it will throw for an out-of-range character, rather than silently mangling it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit reluctant to change behaviour, it might break existing code

m_filter.Write(arg, 0, arg.Length);
}

private void Write(bool arg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're here, could you add some more brackets in the call to Write() below, just to be sure? :)

Write(bytes, true);
}

private static int GetByteCountString(string arg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to suffix all of the GetByteCount methods, should you update the Write methods to have the same? Either way works, but I think we should probably be consistent about it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do - I don't like overloads.

DataColumn col = arg.Columns[i];
colTypes[i] = VariantPrimitiveBase.TypeToEnum(col.DataType);
colNames[i] = col.ColumnName;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocating temporary arrays seems rather unnecessary

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I guess I converted this code too mechanically...

var writeCount = sizeof(Int32);

switch (type)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this borrow GetWriteCounterDelegate()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, but I think it would be a bit weird because the delegate only supports types that can be used in an array. I was trying to keep the counting code as similar to the write code as possible.

@ghost ghost merged commit 36fa25a into proteanic:master Jun 22, 2018
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant